Condensing down that truly awful code offered by the Central Bank of Malta...
... there isn't much to it.
No long numbers at all, you just have to look up the algorithm and go, or as in this case find some working but nasty code and clean it up.
Seems to work against the handful of examples I found (included in the program in a dropdown ComboBox).Code:Function Validate_IBAN(ByVal Account As String) As Boolean Dim intChar As Integer Dim strChar As String Account = UCase$(Account) If Len(Account) > 4 Then Account = Mid$(Account, 5) & Left$(Account, 4) intChar = Len(Account) Do While intChar > 0 strChar = Mid$(Account, intChar, 1) If strChar Like "[A-Z]" Then '55 = Asc("A") - 10 Account = Left$(Account, intChar - 1) _ & CStr(Asc(strChar) - 55) _ & Mid$(Account, intChar + 1) End If intChar = intChar - 1 Loop Do While Len(Account) > 5 Account = CStr(CLng(Left$(Account, 5)) Mod 97) & Mid$(Account, 6) Loop Validate_IBAN = (CLng(Account) Mod 97) = 1 End Function




Reply With Quote