Last active
March 5, 2020 18:28
-
-
Save Nick3523/1ba74ac3598732a150d8f87656760fb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function my_convert(ch As String) As String | |
Dim dict As New Scripting.Dictionary 'Nécessite d'importer Microsoft Scripting Runtime | |
dict.Add Key:="A", Item:=10 | |
dict.Add Key:="B", Item:=11 | |
dict.Add Key:="C", Item:=12 | |
dict.Add Key:="D", Item:=13 | |
dict.Add Key:="E", Item:=14 | |
dict.Add Key:="F", Item:=15 | |
dict.Add Key:="G", Item:=16 | |
dict.Add Key:="H", Item:=17 | |
dict.Add Key:="I", Item:=18 | |
dict.Add Key:="J", Item:=19 | |
dict.Add Key:="K", Item:=20 | |
dict.Add Key:="L", Item:=21 | |
dict.Add Key:="M", Item:=22 | |
dict.Add Key:="N", Item:=23 | |
dict.Add Key:="O", Item:=24 | |
dict.Add Key:="P", Item:=25 | |
dict.Add Key:="Q", Item:=26 | |
dict.Add Key:="R", Item:=27 | |
dict.Add Key:="S", Item:=28 | |
dict.Add Key:="T", Item:=29 | |
dict.Add Key:="U", Item:=30 | |
dict.Add Key:="V", Item:=31 | |
dict.Add Key:="W", Item:=32 | |
dict.Add Key:="X", Item:=33 | |
dict.Add Key:="Y", Item:=34 | |
dict.Add Key:="Z", Item:=35 | |
If dict.Exists(ch) Then | |
my_convert = dict(ch) | |
Else | |
my_convert = ch | |
End If | |
End Function | |
Sub IBANChecker(): | |
Dim rib As String | |
rib = Replace(Replace(ActiveCell.Value, " ", ""), "-", "") 'Supprimer les caratères indésirables | |
rib2 = Right(rib, Len(rib) - 4) & Left(rib, 4) 'Placer les 4 premiers caractères à la fin | |
resultat = 0 | |
Dim ch As String | |
For n = 1 To Len(rib2) | |
ch = Mid(rib2, n, 1) | |
If IsNumeric(ch) Then 'Tour de magie mathématique pour optimiser les calculs.. | |
resultat = (10 * resultat + ch) Mod 97 | |
Else | |
resultat = (100 * resultat + my_convert(ch)) Mod 97 | |
End If | |
Next n | |
If (resultat = 1) Then | |
MsgBox ("L'IBAN est correct") | |
Else | |
MsgBox ("L'IBAN est incorrect :'( ") | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment