Click to See Complete Forum and Search --> : arrays


Pat S
September 14th, 2001, 02:28 PM
Can anyone tell me exactly what this function does?

Dim intLCV As Long
Dim intResult As Long
Static Multiply As Variant

'routing number check digit calculation.
'Returns true if checkdigit is valid, false if
'not.

Multiply = Array(0, 3, 7, 1, 3, 7, 1, 3, 7)

If Len(strRNum) = 9 And IsNumeric(strRNum) Then
For intLCV = 1 To 8
intResult = intResult + (Multiply(intLCV) * CInt(Mid(strRNum, intLCV, 1)))
Next intLCV
If (10 - (intResult Mod 10)) Mod 10 = CInt(Right(strRNum, 1)) Then
CheckDigit = True
Else
CheckDigit = False
End If
Else
CheckDigit = False
End If

JeffB
September 14th, 2001, 06:31 PM
It seems to be some sort of Credit Number validation.

The loop (1 to 8) generates a number by multiplying each number enter in a textbox (strRNum) by a number in the array in this order (3,7,1,3,7,1,3,7)

Example, you enter 111 111 112 as the number (without spaces)
The result will be (3*1)+(7*1)+(1*1)..., so 32

Then, we makes a sort of validation. We divides the results by 10 taking the rest, this rest must be the last number enter in the textbox (strRNum)

In my example, 32 Mod 10 gives 2, 2 is my last number (# 9), so it is valid

I did not try it, but it appears to be that ;)