检查if语句中的多个条件

Abd*_*_88 1 vb.net visual-studio-2008

我有一个表单由用户填写,它有一个复选框,以确定用户帐户是否处于活动状态,如果选中该复选框,我想知道它是否在数据库中有用户名和密码,如果没有msgbox应该出现.我有一个工作,我需要确定if语句...是否正确,如果没有请解释.

      Protected Sub ibtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ibtnSave.Click
    objBU_Accounts_Contacts = New BU_Accounts_Contacts
    Dim err As Integer
    With objBU_Accounts_Contacts
        .FK_AccountId = AccountID
        .ContactEmail = txtConEmail.Text
        .ContactFax = txtConFax.Text
        .ContactMobile = txtConMobile.Text
        .ContactName = txtContactName.Text
        .ContactTitle = txtContactTitle.Text
        .ContactTelephone = txtConTel.Text
        .PharmaLicNo = ""
        .PharmaExpDate = ""
        .HasCredintials = False

        If chkActive.Checked = True Then
            .IsActive = True
        Else
            .IsActive = False
        End If
        .IsApproved = True
        .IsMainContact = False
        .Password = ""
        .Remarks = txtConRemarks.Text
        .UserName = ""
        .SecurityAnswer = ""
        .SecurityQuestion = ""

        If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName) And (objBU_Accounts_Contacts.Password) IsNot Nothing) Then
            err = .Add()
        Else
            MsgBox("E-submission Account Not Created, Plaese Create One First")
        End If

        If ContactID = 0 Then
            err = .Add()
        Else
            .ContactId = ContactID
            err = .Update()
        End If
    End With
    If err = 0 Then
        If SessionVariables.CultureInfo = "en-US" Then
            CtlCommon.ShowMessage(Me.Page, "Saved Successfully")
        Else
            CtlCommon.ShowMessage(Me.Page, "?? ????? ?????")
        End If
    Else
        If SessionVariables.CultureInfo = "en-US" Then
            CtlCommon.ShowMessage(Me.Page, "Error while saving")
        Else
            CtlCommon.ShowMessage(Me.Page, "??? ????? ?????")
        End If
    End If
    FillGrid()
    ClearAll()
End Sub
Run Code Online (Sandbox Code Playgroud)

HAT*_*CHA 5

如果你的意思,这个if语句......

If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName) And (objBU_Accounts_Contacts.Password) IsNot Nothing) Then
Run Code Online (Sandbox Code Playgroud)

你应该改为

If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName IsNot Nothing) And (objBU_Accounts_Contacts.Password IsNot Nothing)) Then
Run Code Online (Sandbox Code Playgroud)

我想说,你可以逐个比较一个对象.