vb.net 在 if 语句中检查多个条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14020449/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check multiple conditions in if statement
提问by Abdulrahman_88
i have a form to be filled by user, it have a check box to find out if the user account is active, if the checkbox is checked, i want to find out if it has a username and password in the database, if not msgbox should appear. i have one am working on i need to be sure about the if statement... is it correct, if not please explain.
我有一个由用户填写的表格,它有一个复选框来确定用户帐户是否处于活动状态,如果选中该复选框,我想确定它是否在数据库中有用户名和密码,如果没有 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
回答by HATCHA
If you meant, this if statement...
如果你的意思是,这个 if 语句......
If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName) And (objBU_Accounts_Contacts.Password) IsNot Nothing) Then
You should change to
你应该改为
If chkActive.Checked = True AndAlso ((objBU_Accounts_Contacts.UserName IsNot Nothing) And (objBU_Accounts_Contacts.Password IsNot Nothing)) Then
I want to say, you can compare one by one object.
我想说,你可以一件一件比较对象。