Correct UPC should be 064200115896 but in the below calculation it return 06420011589-360010
How could I make correctly the odd and even and checkdigit part of the code?
Code: Select all
ProductCode := 11589
UPC := UPC_A(ProductCode)
msgbox, %upc%
UPC_A(ProductCode) {
Suffix := "064200"
UPC := Suffix . ProductCode
OddSum := 0
EvenSum := 0
Loop, 11
{
if(A_Index mod 2 = 1)
OddSum += SubStr(UPC, A_Index, 1)
else
EvenSum += SubStr(UPC, A_Index, 1)
}
CheckDigit := (10 - ((3*OddSum + EvenSum) mod 10)) mod 10
if(CheckDigit = 10) {
CheckDigit := 0
}
UPC .= CheckDigit
return UPC
}