' nf :: Luhn Algorith (Mod 10) :: validate credit card
' ***************************
Dim txtInput As String, txtOutput As String
Dim intLength As Integer, intL1 As Integer, intDigit As Integer, intTmp As Integer
Dim varArrNo() As Variant, intArrProd() As Integer, intSum As Integer
Dim lngEnum As Long
Dim intModulus As Integer
Dim strRes As String
txtInput = Trim(edtAccount.Text)
intLength = Len(txtInput)
If intLength = 0 Then
Exit Sub
End If
Dim varArrNo(1 To intLength) As Variant
Dim intArrProd(1 To intLength) As Integer
intModulus = 10
intDigit = 2
If Not IsNumeric(Right(txtInput, 1)) Then
MsgBox "Only numeric chars are allowed in Modulus 10", vbInformation, ""
Exit Sub
End If
For intL1 = intLength To 1 Step -1
If intDigit = 1 Then
intDigit = 2
ElseIf intDigit = 2 Then
intDigit = 1
End If
varArrNo(intL1) = Val(Mid(txtInput, intL1, 1))
intArrProd(intL1) = intDigit
intTmp = intDigit * Val(Mid(txtInput, intL1, 1))
If intTmp < 10 Then
intSum = intSum + intTmp
Else
intSum = intSum + Val(Left(intTmp, 1))
intSum = intSum + Val(Right(intTmp, 1))
End If
Next
intDigit = intSum Mod 10
If intDigit = 0 Then
strRes = "Verified"
Else
strRes = "not Verified"
End If
MsgBox strRes
' ***************************
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE