Credit card algorithm in Visual Basic?

hi,

can anybody please pass me the sample algorithm foe validating credit cards in Visual Basic?

Thanks!!!

reagrds

David
thiamwahAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
Here you go:


Function ValidateCreditCard(CardNumber As String) As Boolean
temp$ = ""
For i = 1 To Len(CardNumber)
    x$ = Mid$(CardNumber, i, 1)
    If x$ > Chr$(47) And x$ < Chr$(58) Then
        temp$ = temp$ + x$
    End If
Next i
j = Len(temp$) Mod 2
checksum = 0
If j = 0 Then
    'even number of numbers on credit card
    For i = 1 To Len(temp$) Step 2
        k = Val(Mid$(temp$, i, 1)) * 2
        If k > 9 Then
            k = k - 9
        End If
        checksum = checksum + k
    Next i
    For i = 2 To Len(temp$) Step 2
        k = Val(Mid$(temp$, i, 1))
        checksum = checksum + k
    Next i
Else
    'odd number of numbers on credit card
    For i = 2 To Len(temp$) Step 2
        k = Val(Mid$(temp$, i, 1)) * 2
        If k > 9 Then
            k = k - 9
        End If
        checksum = checksum + k
    Next i
    For i = 1 To Len(temp$) Step 2
        k = Val(Mid$(temp$, i, 1))
        checksum = checksum + k
    Next i
End If
checksum = checksum Mod 10
If checksum = 0 Then
    ValidateCreditCard = True
Else
    ValidateCreditCard = False
End If
End Function



Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcriderCommented:
Glad I could help! Thanks for the points!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.