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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BAR CODE SOLUTIONS

Status
Not open for further replies.

acepro

Programmer
Mar 17, 2001
30
US
Greetings
Since this is my First Post on this Forum I thought I might
supply some useful code along with a question. I have been
using this code for over 10 yrs .Works well on many types
of printers using HP PCL & GL control codes. Of course would
work best using laser printers.
My question is this.
Since the procedure relys on direct output to the printer,
How can it be altered to run under VFP since no direct
output is possible in VFP, or is it ?



***************************************
PROCEDURE BARPRN
* Public variables supplied to this procedure are
* UPCPRN (characters to be converted to bar code)
* DRES (resolution of printer to print) suggest 150
* BH (height of bar code in dots) normal 12-24
UPCPRN=ALLTRIM(UPCPRN)
BARm=UPCPRN
******************************** YOUR CODE TO
* DECIDE WHETHER TO PRINT CODE39 OR UPC BAR
* CODE. MAKE SURE YOU HAVE ONLY THE CHARACTERS
* LISTED IN BARUPC & BAR39 SECTIONS BELOW.

IF LEN(UPCPRN)=12 .AND. SUBSTR(UPCPRN,3,1)#'-'
BH=13
DO BARUPC WITH BARm
ELSE
BH=24
DO BAR39 WITH BARm
ENDIF
********************************

IF LEN(BARm)=0
LOOP
ENDIF
P=P+REPLICATE(CHR(0),8-(LEN(P) % 8))
P2=""
Z=CHR(0)
I=1
DO WHILE I<LEN(P)
B=0
FOR J=1 TO 8
B=IIF(SUBSTR(P,I,1)=Z,B*2,B*2+1)
I=I+1
ENDFOR
P2=P2+CHR(B)
ENDDO
??? CHR(27)+&quot;*r0F&quot;
* Put printer in graphics mode
??? CHR(27)+&quot;*t&quot;+DRES+&quot;R&quot;+CHR(27)+&quot;*r1A&quot;
* Set the resolution and start point
FOR H=1 TO BH
* Repeat until desired height BH
??? CHR(27)+&quot;*b&quot;+ALLTRIM(STR(LEN(P2),3))+&quot;W&quot;+P2
* Send byte length and print one row
ENDFOR
??? CHR(27)+&quot;*rB&quot;
* End graphics mode
RETURN
************************
PROCEDURE BAR39
PARAMETERS BARm
PRIVATE ns,ws,nb,wb,wb1,wb2,wb3,wb4
PRIVATE ws1,ws2,ws3,nb1,nb2,nb3,nb4
PRIVATE ns1,ns2,ns3,ns4,msg,t,x
IF TYPE('BARm')#&quot;C&quot;
RETURN &quot;&quot;
ENDIF
* Var must be character type
IF AT(&quot;*&quot;,&quot; &quot;+BARm)>1
RETURN
ENDIF
* Var can not contain *
MSG=&quot;*&quot;+UPPER(BARm)+&quot;*&quot;
* Code 39 starts & ends with an *
ns=CHR(0)+CHR(0)
ws=CHR(0)+CHR(0)+CHR(0)+CHR(0)
nb=CHR(255)
wb=CHR(255)+CHR(255)+CHR(255)
* Set up the PCL codes needed for BAR & SPACE
WB1=wb+ns+nb
WB2=wb+ns+wb
WB3=wb+ws+wb
WB4=wb+ws+nb
WS1=ws+nb+ns
WS2=ws+wb+ns
WS3=ws+nb+ws
NB1=nb+ns+wb
NB2=nb+ns+nb
NB3=nb+ws+wb
NB4=nb+ws+nb
NS1=ns+wb+ws
NS2=ns+nb+ws
NS3=ns+nb+ns
NS4=ns+wb+ns
* DEFINE ALL THE COMBOS NEEDED*
PUBLIC P
p=&quot;&quot;
FOR x=1 TO LEN(MSG)
t=SUBSTR(MSG,x,1)
DO CASE
CASE t=&quot;1&quot;
p=p+WB1+WS1+NB1
CASE t=&quot;2&quot;
p=p+NB1+WS1+NB1
CASE t=&quot;3&quot;
p=p+WB2+WS1+NB2
CASE t=&quot;4&quot;
p=p+NB2+WS2+NB1
CASE t=&quot;5&quot;
p=p+WB1+WS2+NB2
CASE t=&quot;6&quot;
p=p+NB1+WS2+NB2
CASE t=&quot;7&quot;
p=p+NB2+WS1+WB2
CASE t=&quot;8&quot;
p=p+WB1+WS1+WB1
CASE t=&quot;9&quot;
p=p+NB1+WS1+WB1
CASE t=&quot;0&quot;
p=p+NB2+WS2+WB1
CASE t=&quot;A&quot;
p=p+WB1+NS2+NB1
CASE t=&quot;B&quot;
p=p+NB1+NS2+NB1
CASE t=&quot;C&quot;
p=p+WB2+NS2+NB2
CASE t=&quot;D&quot;
p=p+NB2+NS1+NB1
CASE t=&quot;E&quot;
p=p+WB1+NS1+NB2
CASE t=&quot;F&quot;
p=p+NB1+NS1+NB2
CASE t=&quot;G&quot;
p=p+NB2+NS2+WB2
CASE t=&quot;H&quot;
p=p+WB1+NS2+WB1
CASE t=&quot;I&quot;
p=p+NB1+NS2+WB1
CASE t=&quot;J&quot;
p=p+NB2+NS1+WB1
CASE t=&quot;K&quot;
p=p+WB1+NS3+NB3
CASE t=&quot;L&quot;
p=p+NB1+NS3+NB3
CASE t=&quot;M&quot;
p=p+WB2+NS3+NB4
CASE t=&quot;N&quot;
p=p+NB2+NS4+NB3
CASE t=&quot;O&quot;
p=p+WB1+NS4+NB4
CASE t=&quot;P&quot;
p=p+NB1+NS4+NB4
CASE t=&quot;Q&quot;
p=p+NB2+NS3+WB3
CASE t=&quot;R&quot;
p=p+WB1+NS3+WB4
CASE t=&quot;S&quot;
p=p+NB1+NS3+WB4
CASE t=&quot;T&quot;
p=p+NB2+NS4+WB4
CASE t=&quot;U&quot;
p=p+WB4+NS3+NB1
CASE t=&quot;V&quot;
p=p+NB3+NS3+NB1
CASE t=&quot;W&quot;
p=p+WB3+NS3+NB2
CASE t=&quot;X&quot;
p=p+NB4+NS4+NB1
CASE t=&quot;Y&quot;
p=p+WB4+NS4+NB2
CASE t=&quot;Z&quot;
p=p+NB3+NS4+NB2
CASE t=&quot;-&quot;
p=p+NB4+NS3+WB2
CASE t=&quot;.&quot;
p=p+WB4+NS3+WB1
CASE t=&quot; &quot;
p=p+NB3+NS3+WB1
CASE t=&quot;*&quot;
p=p+NB4+NS4+WB1
CASE t=&quot;$&quot;
p=p+NB4+WS3+NB2
CASE t=&quot;/&quot;
p=p+NB4+WS1+NB4
CASE t=&quot;+&quot;
p=p+NB4+NS2+NB4
CASE t=&quot;%&quot;
p=p+NB2+WS3+NB4
OTHERWISE
RETURN
ENDCASE
p=p+ns
* BUILD THE STRING CHAR BY CHAR
ENDFOR
RETURN
************************
PROCEDURE BARupc
PARAMETERS BARm
PRIVATE b1,b2,b3,b4
PRIVATE s1,s2,s3,s4,msg,t
IF TYPE('BARm')#&quot;C&quot;
RETURN &quot;&quot;
ENDIF
MSG=UPPER(BARm)
s1=CHR(0)
s2=CHR(0)+CHR(0)
s3=CHR(0)+CHR(0)+CHR(0)
s4=CHR(0)+CHR(0)+CHR(0)+CHR(0)
b1=CHR(255)
b2=CHR(255)+CHR(255)
b3=CHR(255)+CHR(255)+CHR(255)
b4=CHR(255)+CHR(255)+CHR(255)+CHR(255)
PUBLIC P
p=&quot;&quot;
p=p+b1+s1+b1
FOR x=1 TO 6
t=SUBSTR(MSG,x,1)
DO CASE
CASE t=&quot;1&quot;
p=p+s2+b2+s2+b1
CASE t=&quot;2&quot;
p=p+s2+b1+s2+b2
CASE t=&quot;3&quot;
p=p+s1+b4+s1+b1
CASE t=&quot;4&quot;
p=p+s1+b1+s3+b2
CASE t=&quot;5&quot;
p=p+s1+b2+s3+b1
CASE t=&quot;6&quot;
p=p+s1+b1+s1+b4
CASE t=&quot;7&quot;
p=p+s1+b3+s1+b2
CASE t=&quot;8&quot;
p=p+s1+b2+s1+b3
CASE t=&quot;9&quot;
p=p+s3+b1+s1+b2
CASE t=&quot;0&quot;
p=p+s3+b2+s1+b1
OTHERWISE
RETURN
ENDCASE
ENDFOR
p=p+s1+b1+s1+b1+s1
FOR x=7 TO 12
t=SUBSTR(MSG,x,1)
DO CASE
CASE t=&quot;1&quot;
p=p+b2+s2+b2+s1
CASE t=&quot;2&quot;
p=p+b2+s1+b2+s2
CASE t=&quot;3&quot;
p=p+b1+s4+b1+s1
CASE t=&quot;4&quot;
p=p+b1+s1+b3+s2
CASE t=&quot;5&quot;
p=p+b1+s2+b3+s1
CASE t=&quot;6&quot;
p=p+b1+s1+b1+s4
CASE t=&quot;7&quot;
p=p+b1+s3+b1+s2
CASE t=&quot;8&quot;
p=p+b1+s2+b1+s3
CASE t=&quot;9&quot;
p=p+b3+s1+b1+s2
CASE t=&quot;0&quot;
p=p+b3+s2+b1+s1
OTHERWISE
RETURN
ENDCASE
ENDFOR
p=p+b1+s1+b1
RETURN
Charlie Huff
CJ's Homecenter
From the Star Trek Generation
 
Hi Charlie,

I couldn't quite make sense of the LOOP at the top:
Code:
   IF LEN(BARm)=0
     LOOP
   ENDIF
which precedes any actual loop. Is there a line missing?

But to answer your question, VFP does support ??? and it does go straight to the printer, bypassing any processing by the printer driver. An alternative would be sending it to a text file, and then copying the text file to the printer port.


Thanks for the code,

Chris
 
Or, Load a Barcode font in the printer and just print the character to the printer and let the barcode font convert it.
David W. Grewe
Dave@internationalbid.com
ICQ VFP ActiveList #46145644
 
HI Chris
Sorry about the LooP

IF LEN(BARm)=0
LOOP
ENDIF

I use the routines to generate bin labels and retail bar code stickers.
The LooP is there to prevent empty strings being processed but is
redundent because empty strings are checked in the main prg.
Should be a &quot;Return&quot; if left in.

Thanks for pointing it out.


Charlie Huff
CJ's Homecenter
From the Star Trek Generation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top