par Michael DELIQUE » 24 Oct 2007 à 13:44
- Code : Tout sélectionner
Public Function cleINSEE(wINSEE As String) As Integer
'cette fonction permet de calculer la clé de controle d'un numéro de sécurité sociale
'Déclaration Variables
Dim INSEE As String
Dim Char As String
Dim i As Integer
On Error Goto ErreurHandle
If Trim(wINSEE) = "" Then
cleINSEE = -1
Exit Function
End If
'elimination des caracteres superflux
For i = 1 To Len(Trim(wINSEE))
Char = Mid(wINSEE,i,1)
If Char Like "[a-b,A-B,0-9]" Then
INSEE = INSEE + Ucase(Char)
End If
Char = ""
Next
'si la taille est égale a 15 c'est que la clé est ajouté au numéro
If Len(INSEE) = 15 Then
INSEE = Left(INSEE,13)
End If
If Len(INSEE) <> 13 Then
cleINSEE = -1
Exit Function
End If
' on remplace le code de la corse "2A" ou "2B"
Select Case Mid(INSEE,6,2)
Case "2A"
INSEE = Left(INSEE,5)+"19"+Right(INSEE,6)
Case "2B"
INSEE = Left(INSEE,5)+"18"+Right(INSEE,6)
Case Else
End Select
'vérifie qu'il n'y plus que des chiffres
If INSEE Like "*[a-z,A-Z]*" Then
cleINSEE = -1
Exit Function
End If
cleINSEE = 97-(ModuloBigNumber(INSEE,97))
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 !"
cleINSEE = -1
Exit Function
End Function
- Code : Tout sélectionner
Public Function ModuloBigNumber(wNumber As String, wnbDiviseur As Long) As Integer
'cette fonction permet de faire un modulo sur un tres grand nombre entier ne pouvant pas être géré par la functon Mod
Dim LeftNumber As String
Dim RightNumber As String
Dim i As Integer
On Error Goto ErreurHandle
If Trim(wNumber) = "" Then
ModuloBigNumber = -1
Exit Function
End If
'vérifie qu'il n'y que des chiffres
If wNumber Like "*[!0-9]*" Then
ModuloBigNumber = -1
Exit Function
End If
i = Len(Cstr(wnbDiviseur))
LeftNumber = Left(wNumber, i)
RightNumber = Mid(wNumber, i+1)
Do
LeftNumber = Cstr(Clng(LeftNumber) Mod wnbDiviseur)
LeftNumber= LeftNumber + Left(RightNumber, 1)
RightNumber= Mid(RightNumber, 2)
Loop While RightNumber<>""
ModuloBigNumber = Clng(LeftNumber) Mod wnbDiviseur
RightNumber = ""
LeftNumber = ""
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 !"
ModuloBigNumber = -1
Exit Function
End Function
Cordialement
Michael (SMS-Phobique)
----------------------------
"La théorie, c'est quand on sait tout et que rien ne fonctionne. La pratique, c'est quand tout fonctionne et que personne ne sait pourquoi."
Albert EINSTEIN