Hmmmmmmmmmmmmmmmm ... mmmmmmmmmmmmmmmm ... mmmmmmmmmmm
I am truly lost in the wilderness. I have NO clue as to what input returns the value
000000037489
From your original statement (the other thread), It appears that the
anpostocr function expects a string, so numeric inputs will generally not return the correct response. Even the case of numerics with leading zeroes would generally return an "incorrect" response, as the process would "Truncate" the leading zeroes in the calling argument, so the
value 000021 would return the
string "213" (correct check digit, but incorrect as it "lost" the leading characters).
I have (again!) revised the code to accomodate either Numeric or Character input, by changing the conditional at the top of the program logic to simply provide the conversion from Numeric to (an internal) string which is operated on. This will permit the function to OPERATE with either input - but does not (cannot) correct for the leading zeroes. This limitation could be overcome if htere were 'limits' which apply to the bank code field (e.g. always a fixed length 'integer' type). But any limitations /validation rules of this nature are not stated, so it would be PURE speculation to impose any such 'rule' on the input arg (or the return).
Just to be sure of the process, I've re-posted the complete revised code below, along with a simple test routine to illustrate the return values for various (assumed) input arg values. In the test prog, I placed the return values in the asignment statements for the test values as comments. Hopefully, this will help - so you can at least see the results. Note that I did NOT get the same return value for the lase 'error' - at least not from what I assumed the input to be.
Code:
Public Function basMod11Chk(ChkChr As Variant) As String
'Michael Red 3/21/2002 Adapted from Tek-Tips thread
Dim Idx As Integer
Dim ChkSum As Long
Dim ChkVal As Integer
Dim Wgt As Long
Dim MyStr As String
Dim MyChr As String
Dim MyChkChr As String
If (IsNumeric(ChkChr)) Then
MyChkChr = CStr(ChkChr)
Else
MyChkChr = ChkChr
End If
For Idx = Len(MyChkChr) To 1 Step -1 'One Char at a time - BACKWARDS
MyChr = Mid$(MyChkChr, Idx, 1)
Wgt = Val(MyChr) * (Len(MyChkChr) - Idx + 2)
ChkSum = ChkSum + Wgt
Next Idx
ChkVal = (11 - (ChkSum Mod 11))
If (ChkVal >= 10) Then
ChkVal = ChkVal - 10 '---for case of 10 or 11
End If
basMod11Chk = ChkChr & Trim(str(ChkVal))
End Function
Public Function basTstMod11()
Dim MyTestVal(5) As Variant
MyTestVal(0) = "000021" '0000213
MyTestVal(1) = 21 '213
MyTestVal(2) = 21# '213
MyTestVal(3) = 21.0000000000001 '21.00000000000013
MyTestVal(4) = 3748 '37486
MyTestVal(5) = "00000003748" '000000037486
For Idx = 0 To UBound(MyTestVal)
If (MyTestVal(Isx) <> "") Then
Debug.Print MyTestVal(Idx), basMod11Chk(MyTestVal(Idx))
End If
Next Idx
End Function
MichaelRed
m.red@att.net
There is never time to do it right but there is always time to do it over