PDA

View Full Version : Check Digit Routine


ctaylor@colortech
November 18th, 2009, 06:19 AM
Has anyone had experience with writing a check digit routine? I need to write a modulus 10 check digit routine and I am fairly inexperienced with Javascript and could any help you may have. Thanks in advance. :confused:

ctaylor@colortech
November 18th, 2009, 09:55 AM
I was able to figure it after all. If anyone needs this for the future, I have included the code.

digit1 = StringToNumber(Left(Field("ID ENTITY FEIN1"), 1));
digit2 = StringToNumber(Right(Field("ID ENTITY FEIN1"), 1));
digit3 = StringToNumber(Left(Field("ID ENTITY FEIN2"), 1));
digit4 = StringToNumber(Mid(Field("ID ENTITY FEIN2"), 2, 1));
digit5 = StringToNumber(Mid(Field("ID ENTITY FEIN2"), 3, 1));
digit6 = StringToNumber(Mid(Field("ID ENTITY FEIN2"), 4, 1));
digit7 = StringToNumber(Mid(Field("ID ENTITY FEIN2"), 5, 1));
digit8 = StringToNumber(Mid(Field("ID ENTITY FEIN2"), 6, 1));
digit9 = StringToNumber(Right(Field("ID ENTITY FEIN2"), 1));
result1 = digit1 * 1;
result2 = digit2 * 2;
result3 = digit3 * 1;
result4 = digit4 * 2;
result5 = digit5 * 1;
result6 = digit6 * 2;
result7 = digit7 * 1;
result8 = digit8 * 2;
result9 = digit9 * 1;
result1a = FormatNumber("00", result1);
result2a = FormatNumber("00", result2);
result3a = FormatNumber("00", result3);
result4a = FormatNumber("00", result4);
result5a = FormatNumber("00", result5);
result6a = FormatNumber("00", result6);
result7a = FormatNumber("00", result7);
result8a = FormatNumber("00", result8);
result9a = FormatNumber("00", result9);
add1 = StringToNumber(Left(result1a, 1));
add2 = StringToNumber(Right(result1a, 1));
add3 = StringToNumber(Left(result2a, 1));
add4 = StringToNumber(Right(result2a, 1));
add5 = StringToNumber(Left(result3a, 1));
add6 = StringToNumber(Right(result3a, 1));
add7 = StringToNumber(Left(result4a, 1));
add8 = StringToNumber(Right(result4a, 1));
add9 = StringToNumber(Left(result5a, 1));
add10 = StringToNumber(Right(result5a, 1));
add11 = StringToNumber(Left(result6a, 1));
add12 = StringToNumber(Right(result6a, 1));
add13 = StringToNumber(Left(result7a, 1));
add14 = StringToNumber(Right(result7a, 1));
add15 = StringToNumber(Left(result8a, 1));
add16 = StringToNumber(Right(result8a, 1));
add17 = StringToNumber(Left(result9a, 1));
add18 = StringToNumber(Right(result9a, 1));
digittotal = add1 + add2 + add3 + add4 + add5 + add6 + add7 + add8 + add9 + add10 + add11 + add12 + add13 + add14 + add15 + add16 + add17 + add18;
checkdigit = digittotal % 10
if (checkdigit == 0)
return "0";
else
return 10 - checkdigit;