检查if语句中的多个条件

时间:2012-12-24 10:58:11

标签: 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

1 个答案:

答案 0 :(得分:5)

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

If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName) And (objBU_Accounts_Contacts.Password) IsNot Nothing) Then

你应该改为

If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName IsNot Nothing) And (objBU_Accounts_Contacts.Password IsNot Nothing)) Then

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

相关问题