user3204181
user3204181

Reputation: 1

No converts from string to type boolean but I get the error

 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

Answers (2)

Victor Zakharov
Victor Zakharov

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

Donal
Donal

Reputation: 32713

You need to use the And operator instead of the & operator.

Upvotes: 3

Related Questions