Learn to program in Visual Basic .NET, the right way

Logic - Operators

What are Operators?

Operators are used to compare conditional statements. In Visual Basic .NET there are two types of operators:

  • Comparison Operators
  • Logical Operators

Comparison Operators

Comparison operators are used to compare one value against another. In Visual Basic .NET there are 6 comparison operators:

  • Equals:=
  • Does not Equal:<>
  • Less Than:<
  • Less Than or Equal To:<=
  • Greater Than:>
  • Greater Than or Equal To:>=

Example

The following demonstrates how to use comparison operators:

Fiddle: Live Demo

Logical Operators

Logical operators are used to compare one statement against another. In Visual Basic .NET there are 2 comparison operators:

  • And:AndAlso
  • Or:OrElse

Example

The following demonstrates how to use comparison operators:

Fiddle: Live Demo

Remarks

Logical operators help reduce the amount of ElseIf statements. I would not worry about having too many logical operators; in my opinion it is better to have one long conditional statement if it has the logical operators are setup properly.