UPC function sum of even and odd number
Posted: 21 Jan 2023, 21:00
The below code should calculate all the odd number of 06420011589 and multiply by 3, then calculate the even number. Add the odd number total 57 to the even number total 17 to make 74. Then you need to round up to the next 10s value and make the difference between it and the 74. 80 - 74 should return 6 which is the checkdigit number.
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?
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
}