If strCardNum.Length <> 5 Then
            MessageBox.Show("Please enter a 5 numbers.", _
                             "Georgetown Credit", _
                             MessageBoxButtons.OK, MessageBoxIcon.Information)
        ElseIf Not (Integer.TryParse(strCardNum.Substring(0, 1), intNum1) _
        OrElse Integer.TryParse(strCardNum.Substring(1, 1), intNum2) _
        OrElse Integer.TryParse(strCardNum.Substring(2, 1), intNum3) _
        OrElse Integer.TryParse(strCardNum.Substring(3, 1), intNum4) _
        OrElse Integer.TryParse(strCardNum.Substring(4, 1), intNum5)) Then
            MessageBox.Show("The card number entered is not number")
        Else
            intSumNum = intNum1 + (intNum2 * 2) + intNum3 + (intNum4 * 2)

            intSumNum = Convert.ToInt32(strSumNum)(it won't accept this, how do I get this part convert?)

            If intNum5.ToString() = (strSumNum.Substring(2, 1)) Then
                Me.lblCreditCard.Text = "The credit card number is valid."
            Else
                Me.lblCreditCard.Text = "The credit card number is invalid."
            End If
        End If

Recommended Answers

All 4 Replies

If strCardNum.Length <> 5 Then
            MessageBox.Show("Please enter a 5 numbers.", _
                             "Georgetown Credit", _
                             MessageBoxButtons.OK, MessageBoxIcon.Information)
        ElseIf Not (Integer.TryParse(strCardNum.Substring(0, 1), intNum1) _
        OrElse Integer.TryParse(strCardNum.Substring(1, 1), intNum2) _
        OrElse Integer.TryParse(strCardNum.Substring(2, 1), intNum3) _
        OrElse Integer.TryParse(strCardNum.Substring(3, 1), intNum4) _
        OrElse Integer.TryParse(strCardNum.Substring(4, 1), intNum5)) Then
            MessageBox.Show("The card number entered is not number")
        Else
            intSumNum = intNum1 + (intNum2 * 2) + intNum3 + (intNum4 * 2)
            strSumNum = Str(intSumNum)


            If intNum5.ToString() = (strSumNum.ToString()).Substring(1)(for some reason, it still show invalid answer...I'm missing something? Error part?) Then
                Me.lblCreditCard.Text = "The credit card number is valid."
            Else
                Me.lblCreditCard.Text = "The credit card number is invalid."
            End If
        End If

For some reason The "If intNum5.ToString() = (strSumNum.ToString()).Substring(1)" is overloaded and I need to fix that to find the last digit from strSumNum that is matching up to intNum5. How Do I do that?

If strCardNum.Length <> 5 Then
MessageBox.Show("Please enter a 5 numbers.", _
"Georgetown Credit", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf Not (Integer.TryParse(strCardNum.Substring(0, 1), intNum1) _
OrElse Integer.TryParse(strCardNum.Substring(1, 1), intNum2) _
OrElse Integer.TryParse(strCardNum.Substring(2, 1), intNum3) _
OrElse Integer.TryParse(strCardNum.Substring(3, 1), intNum4) _
OrElse Integer.TryParse(strCardNum.Substring(4, 1), intNum5)) Then
MessageBox.Show("The card number entered is not number")
Else
intSumNum = intNum1 + (intNum2 * 2) + intNum3 + (intNum4 * 2)
strSumNum = Str(intSumNum)


If intNum5.ToString() = (strSumNum.ToString()).Substring(1)Then
Me.lblCreditCard.Text = "The credit card number is valid."
Else
Me.lblCreditCard.Text = "The credit card number is invalid."
End If
End If

I need to fix that to find the last digit from strSumNum that is matching up to intNum5. How Do I do that?

You mean that you just want to get the last digit on strSumNum then compared that last digit on intNum1 to intNum5 is that what you're trying to achieve?

i supposed you want the last digit for strSumNum and compare to all, you can use right function to get the last digit, then do a loop to compare. hope this suggestion wil help, but not so familiar with vb.net but we have vb.net forums guys out there should be able to help you a lot.

I have asked the mods to move this from VB 4/5/6 to VB.Net. I'm sure you will find your solution over there.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.