0

I fear from loop statements that's why I cannot figure this thing out. I understand the concept put I do not have bigger picture. Here I would like to close the application after the person try 3 times putting the wrong password.

Public Class MainForm

    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub PasswordTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordTextBox.Enter
        PasswordTextBox.SelectAll()
    End Sub

    Private Sub PasswordTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordTextBox.TextChanged
        messageLabel.Text = String.Empty

    End Sub

    Private Sub verifyButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles verifyButton.Click
       

        Dim pass As String = String.Empty
        Dim checkPass As String = String.Empty
        Dim counter
       

        pass = PasswordTextBox.Text.ToUpper()

       'I know this part is wrong
        Do
            counter = counter + 1
            If counter > 2 Then
                Exit Do
            End If

        Loop



        If pass Like "MOMO" Then

            If pass.EndsWith(checkPass) Then

                messageLabel.Text = "The correct password was entered. Please click OK to continue."
           
            End If
        Else    
            MessageBox.Show("The correct password was not entered. Please try again", "Password", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        passwordTextBox.Focus()
    End Sub




End Class

Edited by daniss: Wrong information

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Oxiegen
0

Add and change the code in red.

Public Class MainForm
    Private intRetry As Integer = 0
    Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
        Me.Close()
    End Sub

    Private Sub PasswordTextBox_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordTextBox.Enter
        PasswordTextBox.SelectAll()
    End Sub

    Private Sub PasswordTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles PasswordTextBox.TextChanged
        messageLabel.Text = String.Empty

    End Sub

    Private Sub verifyButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles verifyButton.Click
       intRetry += 1

        Dim pass As String = String.Empty
        Dim checkPass As String = String.Empty
        Dim counter
       

        pass = PasswordTextBox.Text.ToUpper()

        If intRetry < 3 AndAlso pass.Equals("MOMO") Then

            If pass.EndsWith(checkPass) Then

                messageLabel.Text = "The correct password was entered. Please click OK to continue."
           
            End If
        ElseIf intRetry >= 3 Then
            MessageBox.Show("The correct password was not entered. Please try again", "Password", _
                MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If

        passwordTextBox.Focus()
    End Sub
End Class
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.