Thanks to adityau at experts exchange.com for this code.
Thanks to Raul Barot.
The program uses the StartDocPrinter, EndDocPrinter, etc. API functions in the winspool.drv library to send data to the printer.
Note that I don't have a line printer so I have not tested this program. Let me know if it needs changes to work.
|
Private Sub PrintLine(ByVal strPrintString As String)
Dim lngPrinter As Long
Dim lngReturn As Long
Dim lngDoc As Long
Dim udtDocInfo As DOCINFO
Dim lngWritten As Long
lngReturn = OpenPrinter(Printer.DeviceName, lngPrinter, _
0)
If lngReturn = 0 Then
MsgBox "The Printer is not recognized"
Exit Sub
End If
udtDocInfo.pDocName = "rcbarot"
udtDocInfo.pOutputFile = vbNullString
udtDocInfo.pDatatype = vbNullString
lngDoc = StartDocPrinter(lngPrinter, 1, udtDocInfo)
Call StartPagePrinter(lngPrinter)
lngReturn = WritePrinter(lngPrinter, ByVal _
strPrintString, Len(strPrintString), lngWritten)
lngReturn = EndPagePrinter(lngPrinter)
lngReturn = EndDocPrinter(lngPrinter)
lngReturn = ClosePrinter(lngPrinter)
End Sub
|