Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17883
Number of posts: 55243

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Printing Barcode in VB 6 Posted by sheenitmathew on 5 Jan 2009 at 3:06 AM
Hello all,

I need to write VB 6 code for Zebra TLP 2844 barcode printer. I have the printer commands with me but don't know how to send them to the printer. I tried MS Comm control but nothing is printed. I also tried Printer.Print but it printed the text only. I could not find any DLL or anything like that for this printer. I got only the Programming Guide which lists the commands. Below is the code I used. (I got the MS Comm settings code from the net). The commands are working when I tried it with the printer's command window.

Public Sub PrintBarcode()
On Error GoTo eHandler
Dim s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11 As String
s0= & vbLf & "N" & vbLf
s1 = "Q25,3" & vbLf 'Set label size
s2 = "q38" & vbLf 'Label width setting
s3 = "D10" & vbLf 'Set printing darkness
s4 = "S4" & vbLf 'Set printing speed
s5 = "R0" & vbLf 'Set left margin
s6 = "B14,39,0,0,2,5,69,N," & Trim(txtItemCode.Text & "") & vbLf 'barcode

'Text
s7 = "A29,0,0,1,1,2,N," & txtCompName.Text & vbLf
s8 = "A20,137,0,1,1,1,N," & txtItemName.Text & vbLf
s9 = "A97,157,0,1,1,1,N," & "Dhs: " & txtPrice.Text & vbLf
s10 = "P" & Val(txtQty.Text & "") & ",1" & vbLf 'Set how many labels to print, Number of copies of the same label.

'Create a single string for the label output.
s11 = s1 & s2 & s3 & s4 & s5 & s6 & s7 & s8 & s9 & s10
With MSComm1
.CommPort = 1
'set the badurate,parity,databits,stopbits for the connection
.Settings = "9600,n,8,1"
'set the DRT and RTS flags
.DTREnable = True
.RTSEnable = True
'enable the oncomm event for every reveived character
.RThreshold = 1
'disable the oncomm event for send characters
.SThreshold = 1
'open the serial port
.PortOpen = True
'Send the label data to the com port.
' .Settings = "115200,N,8,1" 'Default
.Output = s11
.PortOpen = False

End With
Exit Sub
eHandler:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
End Sub

I also tried:

Public Sub PrintBarcode1()
On Error GoTo eHandler
Open "lpt1" For Output As #1

Print #1, vbLf & "N" & vbLf
Print #1, "Q25,3" & vbLf
Print #1, "q38" & vbLf
Print #1, "D10" & vbLf
Print #1, "S4" & vbLf
Print #1, "R0" & vbLf
Print #1, "D10" & vbLf
Print #1, "B14,39,0,0,2,5,69,N," & Trim(txtItemCode.Text) & vbLf
Print #1, "A20,137,0,1,1,1,N," & txtItemName.Text & vbLf
Print #1, "A97,157,0,1,1,1,N," & "Dhs: " & txtPrice.Text & vbLf
Print #1, "A29,0,0,1,1,2,N," & txtCompName.Text & vbLf
Print #1, "P" & Val(txtQty.Text & "") & ",1" & vbLf

Close #1
Exit Sub
eHandler:
MsgBox Err.Description, vbOKOnly + vbCritical, "Error"
End Sub


Both are not working. When I used the second method, the paper is getting inside the printer, but nothing got printed. Please help me to solve this problem. If you can give me the working code, I will be grateful.

Thanks in advance
Sheenit Mathew.
Report
Re: Printing Barcode in VB 6 Posted by roypartha on 13 Feb 2009 at 5:58 AM
Try chaning the "lpt1" to the printer name in your second code, it should work. If the escape code are right.

Partha Roy



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.