如何在If语句VB.NET中使用“Or”

时间:2015-11-30 23:16:55

标签: vb.net

您好我正在尝试使用多个帐户进行简单登录。我一直收到System.InvalidCastException。

     If ViTextBox1.Text = "user1" Or "user2" And ViTextBox2.Text = "pass1" Or "pass2" Then
        MsgBox("Log In Succesful")
        ViTextBox1.Text = "Username"
        ViTextBox2.Text = "Password"
        Me.Hide()
        Form2.Show()
    Else
        MsgBox("Wrong Username Or Password!")
        ViTextBox2.Text = ""
    End If

1 个答案:

答案 0 :(得分:1)

这将解决史蒂夫描述的问题,嵌套测试,以便你可以明确地说User1必须是Pass1而User2必须是Pass2:

If (ViTextBox1.Text = "user1" And ViTextBox2.Text = "pass1") Or (ViTextBox1.Text = "user2" And ViTextBox2.Text = "pass2") Then