You are on page 1of 3

16 digits = 4916366269413076, use: https://dotnetfiddle.

net/ to test it
Code v1:
Public Module Module1

Sub Main()
Dim CCNum, length As Long ' holds -9,223,372,036,854,775,808 through
9,223,372,036,854,775,807
Dim SCCNum As String
Dim answer As Boolean
Console.WriteLine("Enter the 16 digit credit card number")
CCNum = Console.ReadLine()
SCCNum = CCNum.ToString
length = (SCCNum.Length)
Select Case length
Case 16 : answer = validate(SCCNum)
Case Else : Console.WriteLine("The Credit card number is too long, must be
16 digits")
End Select
Select Case answer
Case True : Console.WriteLine("The Credit card is valid")
Case False : Console.WriteLine("The Credit card is Invalid")
End Select
Console.ReadLine()
End Sub
Function validate(SCCNum As String) As Boolean
Dim i, j, temp, array(15), total, check As Integer
array(15) = SCCNum.Substring(15, 1)
check = array(15) 'last digit is check
i = 0
For j = 14 To 7 'reverses order- so A(14) = A(0) and A(0) = A(14)
temp = array(j)
array(j) = array(i)
array(i) = temp
i = i + 1
Next
i = 0
For i = 0 To 14 '1 to 15, all odd positions, 1, 3, 5
should be doubled, therefore 0, 2, 4 should be doubled
Select Case i Mod 2
Case 0 : array(i) = array(i) * 2 'if i(position) is even then
multiply by 2
Select Case array(i)
Case Is > 9 : array(i) = array(i) - 9 'if the number is larger
than 9 then - 9
Case Else
End Select
Case Else
End Select
total = total + array(i) 'add up

Next
total = total + array(15) 'adds check to total to get a multiple of 10
Select Case total Mod 10
Case 0 : Return True
Case Else : Return False
End Select
End Function
End Module

You might also like