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

how to generate barcodes using visual fox pro with the following code

Status
Not open for further replies.

Luiz Eduh

Technical User
Jan 10, 2012
51
US
Hi im using a code found at which generates barcodes using a font called "upca" I just have 1 problem with the last digit. For example im passing the following digits 555555125215 which is a upc number of 12 digits that i have stored on a dbf in VFP9 (please see the link to the image below), If you see on the attached image link, all the numbers are on the barcode except the last number on the right, in my table, which is the upc number above, the last number is 5, but when generating the barcode the last digit is 6. I want to be able to generate the barcode using the string exactly as i have it store on the table. Here is the code im using. All my upc numbers are 12 digits.

***************************
* UPC.prg
* Author : Rahul Moudgill
* Date : 10-10-10
***************************
LPARAMETERS _Code
IF EMPTY(_Code) OR TYPE("_Code")#'C'
RETURN ""
ENDIF

_Code=chkDigit(_Code)

RETURN Str2UPCa(_Code)


*******************
FUNCTION Str2UPCa
*******************
LPARAMETERS _value
_value=ALLTRIM(_value)
LOCAL m.RightVal,m.RightPart,m.MidVal,m.LeftPart,m.LeftVal
m.LeftVal=CHR(80+VAL(LEFT(_value,1)))
m.LeftPart=SUBSTR(_value,2,5)
m.midVal=CHR(112)
m.RightPart=CHRTRAN(SUBSTR(_value,7,5),"0123456789","@ABCDEFGHI")
m.RightVal=CHR(96+VAL(RIGHT(_value,1)))
RETURN m.LeftVal+m.LeftPart+m.midVal+m.RightPart+m.RightVal


*******************
PROCEDURE chkDigit
*******************
LPARAMETERS _value
LOCAL m.AddVal, m.Val13,i
m.AddVal = 0
m.Val13 = 1

FOR m.i = LEN(_value) TO 1 STEP -1
m.Val13 = IIF(m.Val13 = 3,1,3)
m.AddVal = m.AddVal + (VAL(SUBSTR(_value,m.i,1)) * m.Val13)
ENDFOR
RETURN _value + RIGHT(STR(1000-m.AddVal),1)




Base on this code can you please help me determine why the last number is changing when generating the barcode? on the links below on vfpsample.jpg, you'll see how im testing this on the vfp9 command window
Thank You


Links to images and upc font
Image19.jpg

vfpsample.jpg

upca font
 
No idea about your code (I don't have time to learn yet another language), just a comment regarding the UPC value.

A UPC-A value consists of 11 digits, plus a calculated check-digit, making 12 digits in all.

You appear to be passing in all 12 digits (including the correct check-digit of 5 for the 11-digit value 55555512521), but your code is perhaps attempting to calculate another check-digit?
 
I previously answered you in the VFP Forum, but also advised that this question should have been posted here instead of VFP because the question really isn't about VFP use, but about how to calculate a valid UPC-A barcode and then, after that, print it out - the language used is VERY secondary.

You can find the UPC-A specification pretty clearly explained at:

On that site you will find the method of calculating the UPC-A Check Character.

If you doubt the code you have above, then calculate it yourself by hand using the method detailed on the reference site.
NOTE - personally I would have done my own VFP calculation using a different approach.

If, after that, you believe that the code above is not working correctly, write your own code.

In general, regardless of the language used...
Code:
cUPCRawBarcode = < NumSys1 + MfgCode5 + ProdCode5 >
cUPCChkDigit = CalcChkDigit(cUPCBarcodeString)  && Calculate 
cUPCBarcodeString = cUPCRawBarcode + cUPCChkDigit
* --- Now Print COMPLETE Barcode ---
< print it out >

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top