Help i need to have 3 login attempts then the program will lock down but the message box shows up 3 times consecutively, it will close then pops out it will do this for 3 times then it closes ... help pleassseee :(

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
Dim un, pw As String
Dim counter As Integer = 0
un = txtUsername.Text
pw = txtPassword.Text

Do 
    If un = "student" And pw = "21217" Then
        Me.Hide()
        CourseStudy.Show()
    Else
        counter = counter + 1
        MsgBox("Try again", MsgBoxStyle.Critical, "Acess Denied")
        txtPassword.Text = ""
        txtUsername.Text = ""

    End If

Loop While counter <= 2

Me.Close()
Form1.Close()
MessageBox.Show("Program exited, Try again", "Acess Denied")

End Sub

Hi Allyson

I trust that you have already solved your problem, however for purposes of answering this question here are some comments on a possible solution, the issues you experienced are what is known as a logic bug and your code is doing exactly what you described:

  1. Your retry counter should be global to your application and not declared and set within the click event / method you are calling.
  2. The Do - Loop While would simply become an If statement to check if the counter is still less than 2 (assuming you use starting point 0 )
  3. You would need to set your counter to 0 again if the person successfully authenticates the username & password.

Kind regards

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.