×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Function: Mod10 check digit with weights of 7,5,3,2

## Function: Mod10 check digit with weights of 7,5,3,2

(OP)
Need help writing code snippet for Modulus 10 check digit with weights of 7,5,3,2. As shown below:

Thank you!

### RE: Function: Mod10 check digit with weights of 7,5,3,2

#### CODE

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
'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
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 
test

#### CODE

GetCheckDigit(8529831)

Results:

#### CODE -->

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 

### RE: Function: Mod10 check digit with weights of 7,5,3,2

Nice when you get thanks and feedback from your hard work, ain't it Maj?

Darrylles

Never argue with an idiot, he'll bring you down to his level - then beat you with experience.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!