Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing to Eltron Printer - Printing Labels (Need Help)

Status
Not open for further replies.
Mar 9, 2006
93
CA
I am attempting to print to an Eltron 2442 printer to print labels. I have the program working in VB6 and I convert to the program to VB.NET and make some adjustments and then nothing prints out. There are no errors detected and nothing happens. Here is the code that does the printing:

I also have the following functions declared:

Private Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName As String, ByVal phPrn As Long, ByVal pDefault As Object) As Boolean

Private Declare Function StartDocPrinter Lib "winspool.drv" Alias "StartDocPrinterA" (ByVal hPrn As Long, ByVal Level As Long, ByVal pDocInfo As DOC_INFO_1) As Long

Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long

Private Declare Function WritePrinter Lib "winspool.drv" (ByVal hPrn As Long, ByVal pBuf As Object, ByVal cdBuf As Long, ByVal pcWritten As Long) As Long

Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long

Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long

Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrn As Long) As Long

Here is the code that does the actual printing. I send thise method the file where the data is that needs to be printed and the name of the printer.

Private Sub SpoolFile(ByVal sFile As String, ByVal PrnName As String

Dim hPrn As Long
Dim Buffer() As Byte
Dim hFile As Integer
Dim Written As Long
Dim di As DOC_INFO_1
Dim I As Long
Const BufSize As Long = &H4000

Try

di.pDocName = sFile

di.pOutputFile = vbNullString
di.pDatatype = "RAW"

Call OpenPrinter(PrnName, hPrn, 0)
Call StartDocPrinter(hPrn, 1, di)
Call StartPagePrinter(hPrn)

hFile = FreeFile()
FileOpen(hFile, sFile, OpenMode.Binary, OpenAccess.Read)

ReDim Buffer(BufSize)
For I = 1 To LOF(hFile) \ BufSize
FileGet(hFile, Buffer)
Call WritePrinter(hPrn, Buffer, BufSize, Written)
Next I

If LOF(hFile) Mod BufSize Then
ReDim Buffer((LOF(hFile) Mod BufSize) - 1)
FileGet(hFile, Buffer)
Call WritePrinter(hPrn, Buffer, UBound(Buffer), Written)
End If

FileClose(hFile)

Call EndPagePrinter(hPrn)
Call EndDocPrinter(hPrn)
Call ClosePrinter(hPrn)

Catch ex As Exception
MessageBox.Show("Error " & ex.ToString())
End Try
End Sub

Thank you for your help.
Matt
 
try msgboxing these values and see if they are working, or you are just swallow errors. Compare them to the values that you get with vb6

Call OpenPrinter(PrnName, hPrn, 0)
Call StartDocPrinter(hPrn, 1, di)
Call StartPagePrinter(hPrn)


as well are you using .Net 2.0 or 1.1?

-The answer to your problem may not be the answer to your question.
 
I ended up finding some code that helped me get the labels to print. I was using 1.1 and I put message boxes in at one point and the return values were not the same as vb6. It did look like the API calls were just swallowing the errors. Thanks for your reponse.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top