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
***************************
* 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