Hi - anyone got a code snippet for calculating the checksum for Barcode 128, Set A ?
I've inherited some code and the character returned in some instances does not render a barcode that can be scanned.
Issue lies in the barcode checksum we are generating - partuclarly around the "calc" value (the remainder value) !
Any tips appreciated - cheers, Mike
Example code snippet ... not working all the time!
addCheckSum04June(inStr : String) : String updating;
vars
start, stop, cksum, c : Character;
i, sum, wt, calc : Integer;
instring, outstring: String;
begin
i:= 1;
wt := 1;
instring := inStr;
check_npid(instring);
outstring := "Ë"; // Set A, Code 128
sum := 103;
foreach i in 1 to instring.length do
c := instring;
outstring := outstring & c;
sum := sum + ( i * (c.Integer - 32));
endforeach;
calc := sum mod 103;
// Based on http://www.makebarcode.com/specs/code_128.html
// Generally speaking, in Subset A if the checksum is between 0 and 63 inclusive, add the checksum and the ASCII code for a space (32) to obtain the character code.
// If the checksum is 64 or higher, subtract 64 to obtain the character code.
if calc < 64 then
calc := calc+32;
else
calc := calc-64;
endif;
write instring & " calc after = " & calc.String & " " & calc.Character;
//if calc = 0 then
// calc := 228; // WAS 228
//elseif calc < 91 then
// calc := calc + 32;
//else
// calc := calc + 103;
//endif;
outstring := outstring & calc.Character;
outstring := outstring & "Î"; // Stop
return outstring;
end;