If txtFirstName.Text <> "First Name" & txtLastName.Text <> "Last Name" & txtUsername.Text <> "Username" & txtPassword.Text = txtConfirmPassword.Text & txtAge.Text <> "Age ( Years )" & txtHeight.Text <> "Height ( Cm )" & txtWeight.Text <> "Weight ( Kg )" & txtAroundWrist.Text <> "Around Wrist ( Cm )" & ComboBox1.Text <> "" Then
'do something
End If
我总是在vb 2010的第一行( Conversion from string to type boolean is not valid
)中收到 if txtFirstName.Text...
错误。
你有什么建议?
答案 0 :(得分:3)
您需要使用And运算符而不是&amp;操作
答案 1 :(得分:2)
&
用于字符串连接。
您可能来自C / C ++ / C#world,其中&
表示And
。您可以在VB.NET中使用And
,或者更好地使用AndAlso
运算符(相当于C#中的&&
)。像这样:
If txtFirstName.Text <> "First Name" AndAlso
txtLastName.Text <> "Last Name" AndAlso
txtUsername.Text <> "Username" AndAlso
txtPassword.Text = txtConfirmPassword.Text AndAlso
txtAge.Text <> "Age ( Years )" AndAlso
txtHeight.Text <> "Height ( Cm )" AndAlso
txtWeight.Text <> "Weight ( Kg )" AndAlso
txtAroundWrist.Text <> "Around Wrist ( Cm )" AndAlso
ComboBox1.Text <> "" Then
'do something
End If
通常,And
用作按位运算符,而AndAlso
是逻辑运算符。另见: