954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

For loop

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
daniss
Newbie Poster
1 post since Apr 2010
Reputation Points: 10
Solved Threads: 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
Oxiegen
Master Poster
715 posts since Jun 2006
Reputation Points: 87
Solved Threads: 141
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: