Weighted MOD 23 Check Digit 追蹤

0
Avatar
Jack Smith

Hello, 

Struggling to get my head around a specific Check Digit requirement. Hope someone with a bit of VBA knowledge may be able to help? 

I have a 13 digit serial number that is required to be shown as text, with a check digit at the end. Example: BGNL10260123H - where H would be the Check Digit.

Each character in the serial must then be converted into a number.
0 = 48, 1 = 49, upto 9 = 57, then letters A = 65, through to Z = 90.

Each character in the serial number is weighted by its position in the serial:
Position 1 = Weight of 9, down to Position 8 = Weight 2
Then 9 = Weight 10 up to 12 = Weight 13. The final digit has a weight of 0. 

Then the converted number is multiplied by the position weight to give a position value. 
The position values for each character are then added together and a MOD 23 is applied. 
The result of the MOD 23 is then converted into a letter. 

As you may be able to tell, this is quite complicated. Can anyone point me in the right direction? 

Thank you!

1 意見

0
Avatar
Pete Thane
評論操作 永久連結

This would need modifying for your application this routine is a Mod23 check digit for a nine digit code (ie the Named Data Source "code") and includes both a custom check digit Array and a specific setting of weighting for each of the characters so hopefully this may help a bit:

 

Dim CD
CD = Array("B","W","D","F","G","K","Q","V","Y","X","A","S","T","N","J","H","R","P","L","C","Z","M","E")

Value = Format.NamedSubStrings("code").Value

Value1=Left(Value,1)
Value1=Value1* 22

Value2=Left(Value,2)
Value2=Right(Value2,1)
Value2=Value2*21

Value3=Left(Value,3)
Value3=Right(Value3,1)
Value3=Value3*20

Value4=Left(Value,4)
Value4=Right(Value4,1)
Value4=Value4*19

Value5=Left(Value,5)
Value5=Right(Value5,1)
Value5=Value5*18

Value6=Left(Value,6)
Value6=Right(Value6,1)
Value6=Value6*17

Value7=Left(Value,7)
Value7=Right(Value7,1)
Value7=Value7*16

Value8=Left(Value,8)
Value8=Right(Value8,1)
Value8=Value8*15

Value9=Left(Value,9)
Value9=Right(Value9,1)
Value9=Value9*14

Value=Value1+Value2+Value3+Value4+Value5+Value6+Value7+Value8+Value9

Value=Value Mod 23

Value=22-Value

Value= CD(Value)

登入寫評論。