We help IT Professionals succeed at work.
Get Started

EVB code for LUHN Algorithm validation

Last Modified: 2013-12-27
We are using embedded visual basic to check credit card numbers as they are entered into a text box (called 'edtaccount') on a PPC handheld.  The following code works perfectly if I run it in Visual Basic but when I try to compile in EVB it gives me an error on the following lines:

ReDim varArrNo(1 To intLength)
ReDim intArrProd(1 To intLength)
I've attached the code below and am not quite sure why this would compile and work in VB6 but not EVB?  Thanks for the help!
' 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
            intSum = intSum + Val(Left(intTmp, 1))
            intSum = intSum + Val(Right(intTmp, 1))
        End If
    intDigit = intSum Mod 10
    If intDigit = 0 Then
        strRes = "Verified"
        strRes = "not Verified"
    End If
    MsgBox strRes
    ' ***************************

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

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.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE