Calcul Cle RIB
http://fr.wikipedia.org/wiki/Cl%C3%A9_RIB
- Code : Tout sélectionner
Public Function CleRIB(wnbBanque As Integer, wnbGuichet As Integer, wCompte As String) As Integer
'Déclaration Variables
Dim lstValue List As String
Dim Compte As String
Dim Char As String
Dim i As Integer
On Error Goto ErreurHandle
If Abs(wnbBanque) = 0 Then
CleRIB = -1
Exit Function
Elseif Len(Cstr(Abs(wnbBanque)))>5 Then
CleRIB = -1
Exit Function
End If
If Abs(wnbGuichet) = 0 Then
CleRIB = -1
Exit Function
Elseif Len(Cstr(Abs(wnbGuichet)))>5 Then
CleRIB = -1
Exit Function
End If
If Trim(wCompte)="" Then
CleRIB = -1
Exit Function
End If
lstValue("A") = "1"
lstValue("J") = "1"
lstValue("B") = "2"
lstValue("K") = "2"
lstValue("S") = "2"
lstValue("C") = "3"
lstValue("L") = "3"
lstValue("T") = "3"
lstValue("D") = "4"
lstValue("M") = "4"
lstValue("U") = "4"
lstValue("E") = "5"
lstValue("N") = "5"
lstValue("V") = "5"
lstValue("F") = "6"
lstValue("O") = "6"
lstValue("W") = "6"
lstValue("G") = "7"
lstValue("P") = "7"
lstValue("X") = "7"
lstValue("H") = "8"
lstValue("Q") = "8"
lstValue("Y") = "8"
lstValue("I") = "9"
lstValue("R") = "9"
lstValue("Z") = "9"
lstValue("0") = "0"
lstValue("1") = "1"
lstValue("2") = "2"
lstValue("3") = "3"
lstValue("4") = "4"
lstValue("5") = "5"
lstValue("6") = "6"
lstValue("7") = "7"
lstValue("8") = "8"
lstValue("9") = "9"
Compte = ""
'conversion des lettres en chiffres
For i = 1 To Len(Trim(wCompte))
Char = Mid(wCompte,i,1)
If Char Like "*[a-z,A-Z,0-9]*" Then
Compte = Compte + lstValue(Ucase(Char))
End If
Char = ""
Next
Erase lstValue
If Len(Trim(Compte))<>11 Then
CleRIB = -1
Exit Function
End If
CleRIB = 97 - ((89 * Ccur(Abs(wnbBanque)) + 15 * Ccur(Abs(wnbGuichet)) + 76 * Ccur(Left(Compte,6)) + 3 * Ccur(Right(Compte,5))) Mod 97)
Compte = ""
Exit Function
ErreurHandle:
Msgbox "("+Cstr(Getthreadinfo (1))+" Call by "+Cstr(Getthreadinfo(10))+")"+Chr(10)+"Erreur " + Str(Err) + " : "+Chr(10) + Cstr(Error)+". "+Chr(10)+"Ligne N° "+Cstr(Erl),16," ERREUR !"
CleRIB = -1
Exit Function
End Function