Как избежать выполнения условий "если", если первое "если" верно

Shao Cucc спросил: 07 октября 2018 в 12:16 в: vb.net

Я хочу, чтобы мой первый If останавливался на "Incorrect user and password", но он касается второго и третьего If, говоря "incorrect user" и "incorrect password" после "incorrect user and password".

Public Class Form1
    Dim numAttempts As Double = 0    Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
        Dim User As String = "ShaoHecc"
        Dim Password As String = "daedric123"
        Dim loginuser As String
        Dim loginpassword As String
        Dim wrong As String = False        loginpassword = Val(txtpass.Text)
        loginuser = Val(txtuser.Text)
        txtpass.Text = loginpassword
        txtuser.Text = loginuser        If txtuser.Text = User And
            txtpass.Text = Password Then
            MessageBox.Show("Access Granted!")
        ElseIf txtuser.Text = loginuser And
            txtpass.Text = loginpassword Then
            MessageBox.Show("Username and Password incorrect, " & numAttempts & " / 3 attempts left")
        End If        If txtuser.Text = User = False Then
            MessageBox.Show("Username incorrect, you have " & numAttempts & " / 3 attempts left.")
            txtuser.Text = Nothing
        End If        If txtpass.Text = Password = False Then
            MessageBox.Show("Password incorrect, you have " & numAttempts & " / 3 attempts left.")
            txtpass.Text = Nothing
        End If        If numAttempts = 3 Then
            MessageBox.Show("Maxiumum number attempts reached, you have been denied access.")
            Application.Exit()
        Else
            numAttempts = numAttempts + 1
        End If
    End Sub
End Class

0 ответов