-
Oct 6th, 2010, 05:42 PM
#1
Thread Starter
New Member
Printing to Zebra label printer issue
Repeated from VB.Net thread...
I've managed to create a work around for this issue and can now print to the printer using the universal driver for the Zebra printer. Now I think I either have a code issue or there is a command that I am not issuing to the printer.
When I first send from Excel the print out is correct. If I stay in the Excel instance and try to print again I either get nothing out of the printer, or I get every other output printed. I.e. the normal expected sequence is 1,2,3,4 what I'm getting is 1,3,5. This is highly annoying as it works fine if I close Excel and open it again OR I cycle power on the printer.
Some variable somewhere is gumming up the works and I can't figure it out.
I've used the msgbox in place of the printout command and the logic appears to work fine (increments correctly). I've built the command string and saved it to Cell $A$1 to a spreadsheet and then used the printout command to send it to the printer. I've added the pass through symbols to the string that allow the command string to go directly to the printer. Can anyone spot what I'm doing wrong?
Code:
Private Sub CommandButton1_Click()
'check text box values and pass values to main module
sl = StartLabel.Text
el = EndLabel.Text
Site = Site.Text
If Len(sl) = 0 Or Len(el) = 0 Then
MsgBox "Please enter Start and End values"
Exit Sub
End If
If Len(Site) = 0 Then
ans = MsgBox("Are you sure that you do not want to enter a Site name?" & Chr(13) & "The Default 'E-Team' will be printed without a site name", vbYesNo, "Site Name?")
If ans = vbNo Then Exit Sub
End If
' label formatting commands
s = "^XA^PR2~SD30" ' start of label format
f = "^XZ" ' end of label format
O1 = "^FO0,20" ' origin ^FOx,y
O2 = "^FO40,78" ' origin ^FOx,y
O3 = "^FO0,150" ' origin ^FOx,y
F1 = "^AUN,62,7" ' field 1 font
F2 = "^B3N,,62,N" ' Barcode font
F3 = "^ADN,36,4" ' site name font
DS = "^FD" 'data field start
DE = "^FS" 'data field seperator
FB = "^FB400,1,0,C,0" ' Fields (F1 & F3) needs this at the beginning
''Loop resolution
Call lpcnt(sl, el, sv, svl, ev, evl, lp)
iter = lp' number of labels to print
MsgBox lp & " Labels will be printed." & Chr(13) & "Starting at " & sl & " and ending at " & el & "."
nl = sl
'build and print labels
For I = 1 To iter
Str1 = "${" & s & O1 & F1 & FB & DS & nl & DE ' Start of format data
Str2 = O2 & F2 & DS & nl & DE ' Barcode portion of label
Str3 = O3 & F3 & FB & DS & "E-TEAM/" & Site & f & "}$" 'end of format data
Worksheets("LabelData").Range("$A$1") = Str1 & Str2 & Str3 ' build and save command codes
'************************************************
Worksheets("LabelData").Range("$A$1").PrintOut ' send data to passthrough on driver
'Repeat until all labels are printed
' nl = next label, sv1 = length of non number start label
' lz = leading zeros, nv = next value string
x = Len(nl)
For Y = 1 To Len(nl)' find numerical start
If Val(Mid(nl, Y, 1)) = 0 And Mid(nl, Y, 1) <> "0" Then x = x - 1
Next Y
nvn = Val(Right(nl, x)) + 1 ' next value number
nvl = Len(nl) - x ' length of numbers string, x = length of non number string
nv = CStr(nvn) ' next value string
If Len(CStr(nv)) < nvl Then
lz = ""
For h = 1 To (Len(nl) - (x + Len(nv)))' add leading zeros to rebuild label string
lz = lz & "0"
Next h
End If
nl = Left(nl, x) & lz & nv
Next I
Call UserForm_Initialize
End Sub
Private Sub lpcnt(sl, el, sv, svl, ev, evl, lp)
'Determine numeric start value
x = Len(sl)
For I = 1 To Len(sl)
If Val(Mid(sl, I, 1)) = 0 And Mid(sl, I, 1) <> "0" Then x = x - 1
Next I
sv = Val(Right(sl, x))
svl = Len(sl) - x
'Determine numeric end value
x = Len(el)
For I = 1 To Len(el)
If Val(Mid(el, I, 1)) = 0 And Mid(el, I, 1) <> "0" Then x = x - 1
Next I
ev = Val(Right(el, x))
evl = Len(el) - x
' Calculate number of labels to be printed.
lp = ev - sv + 1
End Sub
-
Oct 7th, 2010, 05:57 AM
#2
Re: Printing to Zebra label printer issue
Moved To Office Development
-
Oct 7th, 2010, 03:27 PM
#3
Re: Printing to Zebra label printer issue
has the printer got an initialise sequence you can send by code?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 7th, 2010, 04:35 PM
#4
Thread Starter
New Member
Re: Printing to Zebra label printer issue
Hi Westconn1,
I've looked everywhere, online and in the Zebra printer manuals and I cannot find anything that indicates that there is an initialization string. The only start and stop even mentioned is ^XA and ^XZ which are the flags for the start and end of "formatting", aka the label "page".
The string I send starts and ends with these characters so the printer gets the full package of information. and I even tried to just send the ^XA^XZ string without anything after I print. Which should technically print nothing.
This one has really got me stumped this time.
Phil
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|