sm_ashiq Level: Protégé
 Registered: 01-07-2005 Posts: 4
|
Printer Doesn't Eject paper
Hi friend, I use my programme to print a sales invoice in my dot matrix printer (tvs msp 250 champion).
first i write things to text file and i print the file throu API.
But the problem is the printer stops on the last line and paper never comes out.
"paper tear" feature is enabled in my printer and it works while printing in windows mode.
i think that i miss some code.
when i give code "vbformfeed" printer eject the paper 3.6"
i use roll pape the paper size depends up on number of items in the invoice.
This is the code, please help me to solve my problem
Option Explicit
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, 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 Command1_Click()
Dim lhPrinter As Long
Dim lReturn As Long
Dim lpcWritten As Long
Dim lDoc As Long
Dim sWrittendata As String
Dim MyDocInfo As DOCINFO
Dim Fname
Printer.PaperSize = 256
Printer.Height = 3
Fname = "G:\check\invoice.txt"
lReturn = OpenPrinter("TVS MSP 250/Champion/XL Classic", lhPrinter, 0)
If lReturn = 0 Then
MsgBox "The printer Name you typed wasn't recognised."
Exit Sub
End If
MyDocInfo.pDocName = "Ashiq"
MyDocInfo.pOutputFile = vbNullString
MyDocInfo.pDatatype = vbNullString
lDoc = StartDocPrinter(lhPrinter, 1, MyDocInfo)
Call StartPagePrinter(lhPrinter)
If (lDoc = 0) Then
sWrittendata = Fname
Exit Sub
End If
Open Fname For Input As #1
sWrittendata = ""
While Not EOF(1)
Line Input #1, sWrittendata
sWrittendata = sWrittendata + Chr(13) + Chr(10)
lReturn = WritePrinter(lhPrinter, ByVal sWrittendata, Len(sWrittendata), lpcWritten)
Wend
sWrittendata = vbCrLf & vbFormFeed
lReturn = WritePrinter(lhPrinter, ByVal sWrittendata, Len(sWrittendata), lpcWritten)
lReturn = EndPagePrinter(lhPrinter)
lReturn = EndDocPrinter(lhPrinter)
lReturn = ClosePrinter(lhPrinter)
Close #1
End Sub
thank you
|