Vb Script Required For Mod10 Check Digit Calculation Follow

0
Avatar
Legacy Poster

Hi,

Can someone please help to make a VB script to do the following MOD10 (simplified) check digit calculation with 137137... weighting on a 6 digit number.  

 

Thanks

 

Paul

 

The formula is as follows:

 

Data example 1:  112233

weighting:            137137

 

Each number is then multiplied by the weighing value and then all added up

(1x1) + (1x3) + (2x7) + (2x1) + (3x3) + (3x7) = 50

 

The total is then divided by the Mod number 10

50/10 = 5.0 

 

The remainder is 0 (in this case) which is the check digit, so the answer is:

1122330

 

Data example 2:  123456

weighting:            137137

 

Each number is then multiplied by the weighing value and then all added up

(1x1) + (2x3) + (3x7) + (4x1) + (5x3) + (6x7) = 89

 

The total is then divided by the Mod number 10

89/10 = 8.9 

 

The remainder is 9 (in this case) which is the check digit, so the answer is:

1234569

 

Other Examples
 

Base number Check digit   Final number 123486 8   1234868 000002 4   0000024 000003 1   0000031 000004 8   0000048 000005 5   0000055 000006 2   0000062 000007 9   0000079

This is an Excel formula if that helps:

 

=RIGHT((VALUE(RIGHT(MID(A2,2,1)*'Modulus numbers'!A$1,1))+VALUE(RIGHT(MID(A2,3,1)*'Modulus numbers'!B$1,1))+VALUE(RIGHT(MID(A2,4,1)*'Modulus numbers'!C$1,1))+VALUE(RIGHT(MID(A2,5,1)*'Modulus numbers'!D$1,1))+VALUE(RIGHT(MID(A2,6,1)*'Modulus numbers'!E$1,1))+VALUE(RIGHT(MID(A2,7,1)*'Modulus numbers'!F$1,1))),1)









































 

1 comments

0
Avatar
Legacy Poster
Comment actions Permalink

I had a go at it myself and it looks like it works but there is more than likely a cleaner way to do it.

 

C1 = Mid((Data), 1, 1)* Mid((Weight), 1, 1)

C2 = Mid((Data), 2, 1)* Mid((Weight), 2, 1)

C3 = Mid((Data), 3, 1)* Mid((Weight), 3, 1)

C4 = Mid((Data), 4, 1)* Mid((Weight), 4, 1)

C5 = Mid((Data), 5, 1)* Mid((Weight), 5, 1)

C6 = Mid((Data), 6, 1)* Mid((Weight), 6, 1)

Total = C1 + C2 + C3 + C4 + C5 + C6

Value = Right(Total, 1)

Please sign in to leave a comment.