Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitlePrint text one line at a time to a line printer
DescriptionThis example shows how to print text one line at a time to a line printer in Visual Basic 6 by using printing API functions.
Keywordsline printer, print,
CategoriesGraphics
 
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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated