From: Mike Williams on
"Phil Hunt" <aaa(a)aaa.com> wrote in message
news:%23GyHpLP$KHA.420(a)TK2MSFTNGP02.phx.gbl...

> like Open Printer.Port For Output Access Write As 1
> Print #1, ESCString

That doesn't work any more, especially with USB connected printers. Try the
following instead:

Mike

Option Explicit
Private Declare Function OpenPrinter Lib "winspool.drv" _
Alias "OpenPrinterA" (ByVal pPrinterName As String, _
phPrinter As Long, ByVal pDefault As Long) As Long
Private Declare Function StartDocPrinter Lib "winspool.drv" _
Alias "StartDocPrinterA" (ByVal hPrinter As Long, _
ByVal Level As Long, pDocInfo As DOCINFO) As Long
Private Declare Function StartPagePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function WritePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long, pBuf As Any, _
ByVal cdBuf As Long, pcWritten As Long) As Long
Private Declare Function ClosePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function EndDocPrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Declare Function EndPagePrinter Lib "winspool.drv" _
(ByVal hPrinter As Long) As Long
Private Type DOCINFO
pDocName As String
pOutputFile As String
pDatatype As String
End Type

Private Sub Command1_Click()
Dim myPrinter As Long, myDoc As Long, MyDocInfo As DOCINFO
Dim sWrite As String, charsWritten As Long, retVal As Long
retVal = OpenPrinter(Printer.DeviceName, myPrinter, 0)
If retVal = 0 Then
MsgBox "Printer Not found"
Exit Sub
End If
MyDocInfo.pDocName = "Any Name"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
myDoc = StartDocPrinter(myPrinter, 1, MyDocInfo)
Call StartPagePrinter(myPrinter)
'
' send whatever data you wish here
sWrite = "Hello World." & vbCrLf ' or a Esc sequence or whatever
retVal = WritePrinter(myPrinter, ByVal sWrite, _
Len(sWrite), charsWritten)
'
sWrite = vbFormFeed
retVal = WritePrinter(myPrinter, ByVal sWrite, _
Len(sWrite), charsWritten)
retVal = EndPagePrinter(myPrinter)
retVal = EndDocPrinter(myPrinter)
retVal = ClosePrinter(myPrinter)
End Sub



From: Phil Hunt on
It works up to XP. When you connect to USB, the trick is to set up another
comm or lpt port to the same printer using "printer spool" option. Then the
code would work.

"Mike Williams" <Mike(a)WhiskeyAndCoke.com> wrote in message
news:ODPhirP$KHA.5280(a)TK2MSFTNGP05.phx.gbl...
> "Phil Hunt" <aaa(a)aaa.com> wrote in message
> news:%23GyHpLP$KHA.420(a)TK2MSFTNGP02.phx.gbl...
>
>> like Open Printer.Port For Output Access Write As 1
>> Print #1, ESCString
>
> That doesn't work any more, especially with USB connected printers. Try
> the following instead:
>
> Mike
>
> Option Explicit
> Private Declare Function OpenPrinter Lib "winspool.drv" _
> Alias "OpenPrinterA" (ByVal pPrinterName As String, _
> phPrinter As Long, ByVal pDefault As Long) As Long
> Private Declare Function StartDocPrinter Lib "winspool.drv" _
> Alias "StartDocPrinterA" (ByVal hPrinter As Long, _
> ByVal Level As Long, pDocInfo As DOCINFO) As Long
> Private Declare Function StartPagePrinter Lib "winspool.drv" _
> (ByVal hPrinter As Long) As Long
> Private Declare Function WritePrinter Lib "winspool.drv" _
> (ByVal hPrinter As Long, pBuf As Any, _
> ByVal cdBuf As Long, pcWritten As Long) As Long
> Private Declare Function ClosePrinter Lib "winspool.drv" _
> (ByVal hPrinter As Long) As Long
> Private Declare Function EndDocPrinter Lib "winspool.drv" _
> (ByVal hPrinter As Long) As Long
> Private Declare Function EndPagePrinter Lib "winspool.drv" _
> (ByVal hPrinter As Long) As Long
> Private Type DOCINFO
> pDocName As String
> pOutputFile As String
> pDatatype As String
> End Type
>
> Private Sub Command1_Click()
> Dim myPrinter As Long, myDoc As Long, MyDocInfo As DOCINFO
> Dim sWrite As String, charsWritten As Long, retVal As Long
> retVal = OpenPrinter(Printer.DeviceName, myPrinter, 0)
> If retVal = 0 Then
> MsgBox "Printer Not found"
> Exit Sub
> End If
> MyDocInfo.pDocName = "Any Name"
> MyDocInfo.pOutputFile = vbNullString
> MyDocInfo.pDatatype = vbNullString
> myDoc = StartDocPrinter(myPrinter, 1, MyDocInfo)
> Call StartPagePrinter(myPrinter)
> '
> ' send whatever data you wish here
> sWrite = "Hello World." & vbCrLf ' or a Esc sequence or whatever
> retVal = WritePrinter(myPrinter, ByVal sWrite, _
> Len(sWrite), charsWritten)
> '
> sWrite = vbFormFeed
> retVal = WritePrinter(myPrinter, ByVal sWrite, _
> Len(sWrite), charsWritten)
> retVal = EndPagePrinter(myPrinter)
> retVal = EndDocPrinter(myPrinter)
> retVal = ClosePrinter(myPrinter)
> End Sub
>
>
>


From: Helmut Meukel on
"Helmut Meukel" <Helmut_Meukel(a)NoProvider.de> schrieb im Newsbeitrag
news:htjc39$6ml$1(a)news.eternal-september.org...
> "Jim Madsen" <justme(a)nobody.com> schrieb im Newsbeitrag
> news:%23u6O6GH$KHA.5560(a)TK2MSFTNGP02.phx.gbl...
>> When sending a print job to a printer, how does one send an "escape
>> sequence", to access the fonts installed on the printer itself?
>
>
> Jim,
>
> Why use escape sequences at all?
> How about setting the Printer.Font.Name directly in your code?
> If you don't know the names of the built-in printer fonts, the
> printer driver does. Iterate the fonts collection of the Printer
> object to get the names. Fonts which aren't members of the
> Screen.Fonts collection would be built-in fonts of the Printer.
>
> BTW, I faintly remember a KB article about bypassing the
> Printer object to send Escape Sequences to the printer.
>
> Helmut.
>


Found the article I had in mind but it was related to 16-bit VB3.
Article-ID: Q154078 however is about Win32 and VB:
HOWTO: Send Raw Data to a Printefr using the Win32 API from VB.

Helmut.


From: MikeD on


"Phil Hunt" <aaa(a)aaa.com> wrote in message
news:OYpr37P$KHA.420(a)TK2MSFTNGP02.phx.gbl...
> It works up to XP. When you connect to USB, the trick is to set up another
> comm or lpt port to the same printer using "printer spool" option. Then
> the code would work.


And you're going to tell your users that's what they must do? If you're only
using this for yourself and you don't mind setting up your printer that way,
fine. But you can't force this on end-users.

--
Mike


From: Mike Williams on
"Phil Hunt" <aaa(a)aaa.com> wrote in message
news:OYpr37P$KHA.420(a)TK2MSFTNGP02.phx.gbl...

> It works up to XP. When you connect to USB, the trick
> is to set up another comm or lpt port to the same printer
> using "printer spool" option. Then the code would work.

Well of course that depends on how long the OP's arms are and how far away
his customer is ;-)

Mike




First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Email with VB6?
Next: Identifying Modified Database Fields