Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function GetCheckdigit(VarScanlineData As Variant) As Integer
Dim Weights As New Collection
Dim WeightedDigits As New Collection
Dim I As Integer
Dim J As Integer
Dim NumberOfDigits As Integer
Dim Digit As Integer
Dim WeightedDigit As Integer
Dim WeightedSum As Integer
Dim GrandSum As Integer
Dim GrandSumMod10
Dim strDigit As String
Weights.Add (7)
Weights.Add (5)
Weights.Add (3)
Weights.Add (2)
'Get Number of
NumberOfDigits = Len(CStr(VarScanlineData))
' Not sure here if it is always 7 digits. It is a lot simpler if this is the case
' But I will assume the weight pattern just repeats itself so the scanline data can be any length
For I = 1 To NumberOfDigits
Digit = CInt(Mid(CStr(VarScanlineData), I, 1))
J = J + 1
WeightedDigit = Digit * Weights(J)
Debug.Print "Digit:" & Digit & " Weighted Digit: " & WeightedDigit
If J = Weights.Count Then J = 0
'Add the weighted digits to a collection
WeightedDigits.Add (WeightedDigit)
Next I
For I = 1 To WeightedDigits.Count
WeightedDigit = WeightedDigits(I)
strDigit = CStr(WeightedDigit)
For J = 1 To Len(strDigit)
WeightedSum = WeightedSum + CInt(Mid(strDigit, J, 1))
Next J
Debug.Print "Weighted Sum " & WeightedSum
GrandSum = GrandSum + WeightedSum
WeightedSum = 0
Next I
Debug.Print "GrandSum " & GrandSum
'Mod 10 of Grand Sum
GrandSumMod10 = GrandSum Mod 10
Debug.Print GrandSum & " Mod 10: " & GrandSumMod10
'Get Check digit
If GrandSumMod10 = 0 Then
GetCheckdigit = 0
Else
GetCheckdigit = 10 - GrandSumMod10
End If
Debug.Print "Check digit: " & GetCheckdigit
End Function
GetCheckDigit(8529831)
Digit:8 Weighted Digit: 56
Digit:5 Weighted Digit: 25
Digit:2 Weighted Digit: 6
Digit:9 Weighted Digit: 18
Digit:8 Weighted Digit: 56
Digit:3 Weighted Digit: 15
Digit:1 Weighted Digit: 3
Weighted Sum 11
Weighted Sum 7
Weighted Sum 6
Weighted Sum 9
Weighted Sum 11
Weighted Sum 6
Weighted Sum 3
GrandSum 53
53 Mod 10: 3
Check digit: 7