Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error message when pin and/or account number entered incorrectly

Status
Not open for further replies.

Fay86

Programmer
Mar 30, 2007
12
GB
hey guys..

im really new at using vb.net and i have been set a assignment to design a cashpoint machine.

i need an error message to appear when the account number is entered incorrecly, for example error reading card, and i need a error message to appear when user entered incorrect pin number, however the user is allowed three tries before account is blocked. i have managed the following code, however when the user enters an incorrect account number or pin number both the error messages display rather than the one relating to the incorrect entry..

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 correct = True Then
'aID = "Error reading card"
'MessageBox.Show(aID)
'End If

'If found = True Then
'temp = "You have entered your pin incorrectly " & pinTries & " times"
'MessageBox.Show(temp)
'cashpointscreen.Clear()
'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

im really stuck and i have been working on it for weeks. if anyone has any ideas i would love the advice!

thanks!

 
I agree with dobjsonne. You can set up the code to display the different messages after you set the flags to indicate which situation it is. Try commenting out your current code and starting with what dobjsonne posted:

If cashpointscreen.Text = objDR.GetString(4) then
' Set the flag for the PIN being correct here.
else
' Set the flag for the PIN being wrong here.
end if

If accountID.Text = objDR.GetString(0) then
' Set the flag for the account ID being correct here.
else
' Set the flag for the account ID being wrong here.
end if

Then try to get the desired result by setting up the messages, etc., from there. Sometimes taking a step back like that is the best thing to do.

 
i am trying to get it working however i am having little success. do you mean something like this -

'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

If cashpointscreen.Text = objDR.GetString(4) then
' Set the flag for the PIN being correct here.
found = true
else
' Set the flag for the PIN being wrong here.
found = false
end if

If accountID.Text = objDR.GetString(0) then
' Set the flag for the account ID being correct here.
correct = true
else
' Set the flag for the account ID being wrong here.
correct = false
end if

and then put in the code...

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

or am i way off the mark?





 
on the mark, and closing...

then using the exit sub methods that artyk suggested, you can control which messages are shown, and what priority they have over each other
 
That looks pretty good, you will still need a way to get it not to display both messages, though. Also, if it is setting the value for an incorrect entry to "false" then the "If" statement should check for false, not true. You might try this:

Code:
     If correct = False Then
        aID = "Error reading card"
        MessageBox.Show(aID)
      Else
        If found = False Then
          temp = "You have entered your pin incorrectly " & pinTries & " times"
          MessageBox.Show(temp)
          cashpointscreen.Clear()
          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 If
      End If

 
il give that a go..thanks guys. the only other thing im concerned about is the part that allows the groupbox which is called screen to be enabled and visible if the pin and account number is entered correctly. originally it the code was like this ..

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


where would i place this in the new layout of the code?
 
i entered this 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

If cashpointscreen.Text = objDR.GetString(4) Then
' Set the flag for the PIN being correct here.
found = True
Else
' Set the flag for the PIN being wrong here.
found = False
End If

If found & correct = True Then
Screen.Enabled = True
Screen.Visible = True
End If

If accountID.Text = objDR.GetString(0) Then
' Set the flag for the account ID being correct here.
correct = True
Else
' Set the flag for the account ID being wrong here.
correct = False
End If

If correct = False Then
aID = "Error reading card"
MessageBox.Show(aID)
Else
If found = False Then
temp = "You have entered your pin incorrectly " & pinTries & " times"
MessageBox.Show(temp)
cashpointscreen.Clear()
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 If
End If

End Sub

however it came up with an error on this line -
If cashpointscreen.Text = objDR.GetString(4) Then

the error said -

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: No data exists for the row/column.

i know there is data in the database and it is relating to the correct row because it was working before

 
It would be in an "Else" after the first "End If".

Like this:

End If
Else
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
End If
End If
End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top