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 create a check digit for a barcode

Status
Not open for further replies.

BandOQ4b

Programmer
Jul 22, 2010
19
0
0
US
I have a field called Private_Label_Barcode that I need to read each digit and decided if odd or even. all the odd digits are to be added together, and all the even digits added together. I know that I will need to use a loop. I can't figure how to use the value of the digit found in each pass of the loop. Here is what I have so far. The words 'odd' and 'even' are place holders for the code I need to figure out.

Local NumberVar Even_Num := 0;
Local NumberVar Odd_Num := 0;
Local NumberVar strLen := Length ({Private_Label_Barcode});
Local NumberVar i;

For i := 1 To strLen Do
(
if ToNumber (Left ({{Private_Label_Barcode}, 1)) Mod 2 = 0
then 'even'
else 'odd'
);

Odd_Num + (Even_Num * 3) //Check Digit Result

Thanks in advance for assistance!!!
 

Code:
Local NumberVar Even_Num ;
 Local NumberVar Odd_Num ;
local stringvar data := totext({Private_Label_Barcode},"#");
 Local NumberVar strLen := Length(data);
 Local NumberVar i;

 For i := 1 To strLen Do
 (
 if ToNumber(mid(data, i,1)) Mod 2 = 0
 then Even_Num := Even_Num +ToNumber(mid(data, i,1))
 else Odd_Num := Odd_Num + ToNumber(mid(data, i,1));
 );

Odd_Num + (Even_Num * 3)

_____________________________________
Crystal Reports 2011 and XI
Intersystems Cache 2012 ODBC connection

 
Thank you very much!
I knew that I was close, but just couldn't see the last part in my mind!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top