vb.net 2005 login with different outcomes?

  • 13 years ago

    i would be really greatful for some guidance on my code...im new at using VB.net and im having great difficulty with getting the program to do the following -

    im trying to get the following outcomes -

    1 - Both account number and PIN are correct.

    2 - The PIN is correct, but the account number is wrong.

    3 - The PIN is wrong, but the account number is correct.

    4 - Both the PIN is wrong and the account number is wrong.





    however outcomes two and three are displaying both error messages and not the error message relating to the incorrect login - heres my code

    Private Sub EnterButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnterButton.Click
            'set the pin to only three tries
            pinTries = pinTries + 1
            Dim temp As String
            Dim found As Boolean
            found = True

            Dim aID As String
            Dim correct As Boolean
            correct = True

            While objDR.Read()
                'enter both correct pin and account ID to gain access to account details
                If cashpointscreen.Text = objDR.GetString(4) And accountID.Text = objDR.GetString(0) Then
                    Screen.Enabled = True
                    Screen.Visible = True
                    found = False
                    correct = False
                    'Else
                    'found = True
                    'correct = False
                End If
            End While

            If found = True Then
                temp = "You have entered your pin incorrectly " & pinTries & " times"
                MessageBox.Show(temp)
                cashpointscreen.Clear()
            End If

            if correct = True Then
            aID = "Error reading card"
            MessageBox.Show(aID)
            End If

            If pinTries = 3 Then
                'message box telling user they have entered pin incorrect three times
                MessageBox.Show("You Have Entered your pin incorrect 3 times - your account will now be blocked")
                'disable the box so user cannot attempt to enter pin again
                EnterButton.Enabled = False
                EnterButton.Visible = False
                'cashpointscreen.Clear()
            End If

        End Sub











































    Thanks!

  • 13 years ago

    This is because in order for the valueof either found or correct to get changed, then the all emcompassing statement

       If cashpointscreen.Text = objDR.GetString(4) And accountID.Text = objDR.GetString(0) Then

    must be true.

    What you should be doing is breaking that up to something somewhat simpiler like this:

    found = false

    correct = false

    If cashpointscreen.Text = objDR.GetString(4)

       found = true

    end if

    if accountID.Text = objDR.GetString(0) Then

       correct = true

    end if

    if found and correct then 'pin and accountID are right

                    Screen.Enabled = True
                    Screen.Visible = True


    elseif found then 'pin must be correct, acountID is wrong

            aID = "Error reading card"
            MessageBox.Show(aID)


    elseif correct then 'accountID is correct, pin is wrong

                temp = "You have entered your pin incorrectly " & pinTries & " times"
                MessageBox.Show(temp)
                cashpointscreen.Clear()


    else  'pin and acountid is wrong

          temp= "You enetered nothing correctlly!"

    end if

    This assumes that I that 'found' indicates that the pin if valid, and 'correct' indicates the accountID is valid

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The trouble with programmers is that you can never tell what a programmer is doing until it's too late.” - Seymour Cray