I am writing a programme that allows a user to enter personal details but each detail is limited by character length or something like that. I need it to allow the user to enter the details wrong 5 time before being cleared and sent back to a previous form. Im currently trying to use a loop for this but at the moment when you press the enter details button it just loops 5 times straight away and sends the user back without the user being able to change details and try again. Here is what I have so far.
Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click
'Declare variables
'This is the form that i will only allow the operator to enter 5 mistakes before being locked out
Dim strStreetAddress As String = txtStreetAddress.Text
Dim strTown As String = txtTown.Text
Dim strCounty As String = txtCounty.Text
Dim strEircode As String = txtEircode.Text
Dim mskPhoneNumber As String = mskNumber.Text
Dim intErrorCount As Integer = 0
'set up if statements
Do Until intErrorCount = 5
If strStreetAddress.Length = 0 Or strTown.Length = 0 Or strCounty.Length = 0 Or mskPhoneNumber.Length = 0 Or strEircode.Length = 0 Then
intErrorCount += 1
MessageBox.Show("One or more details have not been enterred")
txtStreetAddress.Clear()
txtCounty.Clear()
txtEircode.Clear()
txtTown.Clear()
mskNumber.Clear()
ElseIf strStreetAddress.Length > 50 Or strTown.Length > 15 Or strCounty.Length > 10 Or strEircode.Length <> 7 Or mskPhoneNumber.Length <> 10 Then
intErrorCount += 1
MessageBox.Show("One or more detais has been entered incorrectly")
txtStreetAddress.Clear()
txtCounty.Clear()
txtEircode.Clear()
txtTown.Clear()
mskNumber.Clear()
Else MessageBox.Show("All Details Entered Correctly")
Me.Hide()
frmPurchaseScreen.Show()
End If
Loop
'if errorcount reaches 5 then operator must login again and restart
If intErrorCount = 5 Then
MessageBox.Show("You have made too many errors, you must Login again")
Me.Hide()
frmLogin.Show()
End If
End Sub
Private Sub txtErrorCount_TextChanged(sender As Object, e As EventArgs) Handles txtErrorCount.TextChanged
End Sub
End Class
Aucun commentaire:
Enregistrer un commentaire