HI all,
Im working with a client’s existing code that his previous web developer did in vbscript. I need it in javascript. This bit of code should validate a sample number, so for example a typical number generated today would be 503021001H. The below is the small virtual basic routine that they use to check that the check letter on the end of a sample number is correct.
Dim SpecNo As String
Dim Offset As Integer = 1
Dim i As Integer
Dim x As Integer = 0
Dim Sum As Integer
Dim CLStr As String = "BWDFGKQVYXASTNJHRPLCZME"
Dim CheckLet As Char
SpecNo = TextBox1.Text
For i = 0 To 8
Sum = Sum + (Val(SpecNo(x)) * (23 - Offset))
Offset = Offset + 1
x = x + 1
Next i
CheckLet = CLStr((23 - (Sum Mod 23)) - 1)
However I cant get this in javascript to work, and no online vbscript/javascript converters seem to work. Can anyone help?
Thanks
Not sure I understand what all of that vbScript is supposed to be doing but the following should be close.
var SpecNo;
var Offset = 1;
var i;
var x = 0;
var Sum;
var CLStr = "BWDFGKQVYXASTNJHRPLCZME";
var CheckLet;
var SpecNo = document.getelementById('TextBox1').text; // possibly
for (i = 0; i < 8; ++i) {
Sum = Sum + (SpecNo.slice(x,1)) * (23 - Offset));
Offset = Offset + 1;
x = x + 1;
}
CheckLet = CLStr.slice((23 - (Sum % 23)) - 1),1);
Hi felgall,
Im still having problems with this. It seems to always want to return “B” (the first letter in the CLStr string). So maybe the code is not correctly cycling through the CLStr string?
Thanks