J
James
I have a function that will check the digits in a credit
card to see if there valid. But, I do not know where to
put the cose or what to do to make it work. The code is
as follows:
Function CheckCard(CreditCardNumber As String) As Boolean
Dim Counter As Integer, TmpInt As Integer
Dim Answer As Integer
Counter = 1
TmpInt = 0
While Counter <= Len(CreditCardNumber)
If (Len(CreditCardNumber) Mod 2) Then
TmpInt = Val(Mid$(CreditCardNumber, Counter,
1))
If Not (Counter Mod 2) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
Counter = Counter + 1
Else
TmpInt = Val(Mid$(CreditCardNumber, Counter,
1))
If (Counter Mod 2) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
Counter = Counter + 1
End If
Wend
Answer = Answer Mod 10
If Answer = 0 Then CheckCard = True
End Function
card to see if there valid. But, I do not know where to
put the cose or what to do to make it work. The code is
as follows:
Function CheckCard(CreditCardNumber As String) As Boolean
Dim Counter As Integer, TmpInt As Integer
Dim Answer As Integer
Counter = 1
TmpInt = 0
While Counter <= Len(CreditCardNumber)
If (Len(CreditCardNumber) Mod 2) Then
TmpInt = Val(Mid$(CreditCardNumber, Counter,
1))
If Not (Counter Mod 2) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
Counter = Counter + 1
Else
TmpInt = Val(Mid$(CreditCardNumber, Counter,
1))
If (Counter Mod 2) Then
TmpInt = TmpInt * 2
If TmpInt > 9 Then TmpInt = TmpInt - 9
End If
Answer = Answer + TmpInt
Counter = Counter + 1
End If
Wend
Answer = Answer Mod 10
If Answer = 0 Then CheckCard = True
End Function