par Michael DELIQUE » 24 Oct 2007 à 15:54
- Code : Tout sélectionner
Function isValideCB(wNumero As String) As Integer
'teste si le N° d'une carte de crédit est valide
'Déclaration Variables
Dim Numero As String
Dim Char As String
Dim nbChar As String
Dim i As Integer
Dim nb1 As Integer
Dim nb2 As Integer
On Error Goto ErreurHandle
If Trim(wNumero) = "" Then
isValideCB = False
Exit Function
End If
For i = 1 To Len(wNumero)
Char = Mid(wNumero,i,1)
If Char Like "[0-9]" Then
Numero = Numero + Trim(Char)
End If
Char = ""
Next
If Len(Numero)<>16 Then
isValideCB = False
Exit Function
End If
For i = 1 To Len(Numero)
nbChar = Cint(Mid(Numero, i ,1))
If ((i - 1) Mod 2) = 0 Then
If (nbChar * 2) > 9 Then
nb1 = nb1 + 1 + ((nbChar * 2) - 10)
Else
nb1 = nb1 + (nbChar* 2)
End If
Else
nb2 = nb2 + nbChar
End If
Next
isValideCB = False
If (nb1 + nb2) <> 0 Then
If ((nb1 + nb2) Mod 10) = 0 Then
isValideCB = True
End If
End If
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 !"
isValideCB = False
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