Reputation: 1
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
I always get the Conversion from string to type boolean is not valid
error in the first line(if txtFirstName.Text...
) in vb 2010.
What do you suggest?
Upvotes: 0
Views: 104
Reputation: 26424
&
in VB.NET is for string concatenation.
You are probably coming from C/C++/C# world, where &
means And
. You can use And
in VB.NET, or better use AndAlso
operator (equivalent to &&
in C#). Like this:
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
Generally, And
is used as a bitwise operator, while AndAlso
is a logical operator. See also:
Upvotes: 2