Jump to content

Check Sum


anixon
 Share

Recommended Posts

Is there a check sum #include based on the UPC check formula been written for AutoIT? The the last digit in the number is the check sum and is derived by applying a formula to the first digits 'excluding the check sum number' and subtracting that number from 10.

This code works on 9 digits

#include <Array.au3>

dim $CheckSum[9]
$CheckDigit = 123456782

;//Populate The Checksum Array
For $i = 0 to UBound( $CheckSum ) - 1
    $CheckSum[$i] = Stringmid($CheckDigit, $i, 1)
Next
;Calculate the CheckSum
$CheckSumOdd = ($CheckSum[1] + $CheckSum[3] + $CheckSum[5] + $CheckSum[7]) * 3
$CheckSumEven = $CheckSum[2] + $CheckSum[4] + $CheckSum[6] + $CheckSum[8]
$CheckSumCal = 10 - StringRight($CheckSumOdd + $CheckSumEven,1)
Msgbox(0,"",$CheckSumCal)
Edited by anixon
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...