Printing Barcode in VB 6 - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Printing Barcode in VB 6

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.

Comments

Sign In or Register to comment.