Thread: CheckIBAN
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Filips Benoit[_2_] Filips Benoit[_2_] is offline
external usenet poster
 
Posts: 27
Default CheckIBAN

Dear all,

Why overflow-error on mod-function ???


Public Function CheckIBAN(ByVal strIBAN As String) As Boolean

'1. BE62510007547061
'2. 510007547061 BE62
'3. 510007547061111462
'4. De modulus 97 (remainder of div 97) 510007547061111462 /97 remainder =
1

On Error GoTo Errhandling

Dim strTemp As String
Dim strAllDigits As String
Dim strToken As String
Dim iLoop As Integer
Dim IBANtotalNum As Double
Dim iModulus As Integer

CheckIBAN = False

strTemp = Replace(strIBAN, " ", "")
strTemp = right$(strTemp, Len(strTemp) - 4) & Left$(strTemp, 4): MsgBox
strTemp
For iLoop = 1 To Len(strTemp)
strToken = UCase(Mid$(strTemp, iLoop, 1))
If Not IsNumeric(strToken) Then
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", strToken) = 0 Then
Exit For
Else
strToken = CStr(Asc(strToken) - 55)
End If
End If
strAllDigits = strAllDigits & strToken
Next iLoop

MsgBox strAllDigits & " len=" & Len(strAllDigits)

IBANtotalNum = CDec(strAllDigits): MsgBox "decimal = " & IBANtotalNum
iModulus = IBANtotalNum Mod 97
If iModulus = 1 Then CheckIBAN = True

Exit Function

Errhandling:
MsgBox err.Number & " " & err.Description
End Function