VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Prints real-time line by line. Does not spool and waste paper. Put code that is in form load into a

by Rachel D Kozlowski (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 1st October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Prints real-time line by line. Does not spool and waste paper. Put code that is in form load into any subroutine and it should work fine. Just

API Declarations


Dim sWrittenData As String

Rate Prints real-time line by line. Does not spool and waste paper. Put code that is in form load into a



'The problem with the Printer object Printer.print is that it spools all 
'the data until
'the buffer is filled and then prints.  If you want to print realtime and do
'not want to waste paper this program prints and clears the buffer by opening
'the printer object, printing and then closing the object.
'The code in form load can be called in any subroutine.  It was put into form
'load for demonstration purposes only.
Private Type DOCINFO
          pDocName As String
          pOutputFile As String
          pDatatype As String
End Type

      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 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 Sub Form_Load()
'Setting printer properties for report
    Printer.ScaleMode = vbInches
    Printer.FontSize = 12
    Printer.FontName = "Arial"

'The code below can be placed in any subroutine to be called, you do not have
'to put it in form load.
 sWrittenData = "Hi there!"
 Call PrintNow(sWrittenData)

End Sub

Private Sub PrintNow(sWrittenData As String)
          Dim lhPrinter As Long
          Dim lReturn As Long
          Dim lpcWritten As Long
          Dim lDoc As Long
          
          Dim MyDocInfo As DOCINFO
          lReturn = OpenPrinter(Printer.DeviceName, lhPrinter, 0)
          If lReturn = 0 Then
              MsgBox "The Printer Name you typed wasn't recognized."
              Exit Sub
          End If
          MyDocInfo.pDocName = "Document 1"
          MyDocInfo.pOutputFile = vbNullString
          MyDocInfo.pDatatype = vbNullString
          lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
          Call StartPagePrinter(lhPrinter)
          sWrittenData = sWrittenData & vbCrLf
          lReturn = WritePrinter(lhPrinter, ByVal sWrittenData, _
             Len(sWrittenData), lpcWritten)
          lReturn = EndPagePrinter(lhPrinter)
          lReturn = EndDocPrinter(lhPrinter)
          lReturn = ClosePrinter(lhPrinter)
End Sub


Download this snippet    Add to My Saved Code

Prints real-time line by line. Does not spool and waste paper. Put code that is in form load into a Comments

No comments have been posted about Prints real-time line by line. Does not spool and waste paper. Put code that is in form load into a. Why not be the first to post a comment about Prints real-time line by line. Does not spool and waste paper. Put code that is in form load into a.

Post your comment

Subject:
Message:
0/1000 characters