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!

 
You might throw in an Exit Sub within the "If" statement right before the "End If".
 
on which end if? i have coded some of the code out because it doesnt quiet work and is giving me problems
 
this is the entire code for with the end sub -

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

If MoneytoTakeOut.Visible = True Then
tempValue = tempValue - Val(MoneytoTakeOut.Text)
TextBox2.Text = tempValue
OleDbConnection1.Close()
OleDbConnection1.Open()
'make withdrawl update to the accounts table - update balance field
Dim aSQL As String
aSQL = "UPDATE Accounts SET balance = " & tempValue & " WHERE PIN = '" & cashpointscreen.Text & "'"
OleDbCommand1.CommandText = aSQL
OleDbCommand1.Connection = OleDbConnection1
OleDbCommand1.ExecuteNonQuery()
OleDbConnection1.Close()
End If

End Sub

i didnt include the end sub originally because i didnt post all of my code. above is the entire code for my problem
 
My advice would be to ignore the code for the time being, and just work out how the program flows, and how you want it to flow.
 
Put the Exit Sub in any and all If statements that require the code execution to stop once the error is encountered. For example, if you want it to stop after the error "Error reading card", place the Exit Sub directly after the line "MessageBox.Show(aID)". Do the same for all errors that require further user action.
 
by inserting an end sub for example where you said directly after the line "MessageBox.Show(aID)" will that prevent the other from executing because it is essential that this bit of code executes once the user gains access -

If MoneytoTakeOut.Visible = True Then
tempValue = tempValue - Val(MoneytoTakeOut.Text)
TextBox2.Text = tempValue
OleDbConnection1.Close()
OleDbConnection1.Open()
'make withdrawl update to the accounts table - update balance field
Dim aSQL As String
aSQL = "UPDATE Accounts SET balance = " & tempValue & " WHERE PIN = '" & cashpointscreen.Text & "'"
OleDbCommand1.CommandText = aSQL
OleDbCommand1.Connection = OleDbConnection1
OleDbCommand1.ExecuteNonQuery()
OleDbConnection1.Close()
End If

 
An Exit Sub (not an End Sub) is what is commonly used in that situation when further action is required from the user to re-enter or correct some data. If it is preventing the other code from executing it would be because there is an error that the user needs to correct before the other code is executed. It shouldn't keep any code from running if and when it supposed to run, only if there is a problem. Does that make sense? What I'm getting at is this: if there is an error, the code you posted last should not run. And if there is not an error it should run. Is that correct? In that case you would want to stop that code from executing when an error is encountered. So it needs to stop that code from executing, or your still back in the same situation.
 
i tried using the exit sub and it didnt solve my problem sorry.

ive reduced the code to the following -

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

what i need to code to do is if the pin is entered incorrectly then it says

You have entered your pin incorrectly 1 times

if you enter the time incorrectly twice then it says

You have entered your pin incorrectly 2 times..etc

the code is doing this however when the account number is entered incorrectly it should say error reading the card. however it is coming up with You have entered your pin incorrectly 1 times and then the message error reading the card when the pin has been entered correctly. i need the code to only show the correct message according to what has been entered incorrectly
 
When either the pin is wrong or the account number is wrong, how do you think the code acts in a different way?
 
im sorry i dont understand what you mean. i just need the code to display the the correct error message according to the error inputted by the user
 
You have four situations that could happen:

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.

Depending on which situation it is, some portions of the code will run, and some portions of the code will be skipped.

The code that you have written, acts the same in situation 2 and situation 3.

Try and make sure you do not comment out any part of the code that is actually important.

Regards

J
 
It should look something like this:

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)
        Exit Sub
        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

It shouldn't display "You have entered your pin incorrectly 3 times..." if the account number is wrong. It should hit the Exit Sub and halt the execution of the code. Also you might take a closer look at how and when you are setting the "found" and "correct" values.
 
i agree with what you are saying and i know the code acts the same in situtation 2 and 3 but i really have no clue how to fix the error. i obviously want the correct error to appear when siutation 2 arises and the other error to run when situtation 3 arises. but how i get the code to do this i have no idea. i personally cant see a problem with my code but there obiviously is one otherwise it would run correctly
 
i have tried placing the exit sub there and it will display the pin part however if the account number is incorrect then it will display no message at all
 
Your code says this:

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

What you could try instead is something like this:

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

This way depending on which situation it is, 1 2 3 or 4, the error/success flags will be set accordingly.

Because you need to make sure that your error/success flags are being set correctly before you can even contemplate how the program will react to the different situations.

Hope this helps

J
 
Try changing that messagebox statement to be something like:

MsgBox("Error reading card",MsgBoxStyle.Exclamation,"Error")

Probably what's happening is it's displaying the messagebox, but not waiting for the user's response so it's appearing and disappearing too quickly to see.
 
Never known a messagebox to close itself before ...
 
i can see you logic in taking the code in steps like you have said -

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

however i think i need to keep them together in order to allow my screen to show if the correct pin and account number is correct. i have tried you method and i feel that if i could get it working it would be a great solution however i really am new at this program and im finding the whole thing very difficult. i only have to the end of the week to solve my problem, ive been working on it for a month. i dont think im a natural at it
 
Fay86
Try doing a googlr search on the following terms:
login code vb net -asp -asp.net. There are several examples that I think will help you get to where you need to be.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top