This documentation is archived and is not being maintained.

Boolean Operator Changes in Visual Basic

Visual Basic .NET removes two Boolean operators and adds two others to improve performance.

Visual Basic 6.0

In Visual Basic 6.0, Boolean operators — And, Or, Not, and Xor — always evaluate all the expressions in their operands.

You use the Eqv and Imp operators to perform logical equivalences and implications on two expressions.

Visual Basic .NET

In Visual Basic .NET, the And, Or, Not, and Xor operators still evaluate all expressions contributing to their operands. Visual Basic .NET also introduces two new operators, AndAlso and OrElse, that can reduce execution time by short-circuiting logical evaluations. If the first operand of an AndAlso operator evaluates to False, the second operand is not evaluated. Similarly, if the first operand of an OrElse operator evaluates to True, the second operand is not evaluated.

Note   You should be careful using short-circuiting operators. If the second operand contains a procedure call, you cannot rely on that procedure being called every time the operator executes.

The Eqv and Imp operators are not supported. Use the equals (=) comparison operator in place of Eqv for both logical and bitwise evaluations. You can replace the logical Imp operator with an expression using the Not and Or operators, as shown in the following example:

Result = A Imp B         ' True unless A is True and B is False. 
Result = (Not A) Or B    ' Same as A Imp B.

You can replace a bitwise Imp in the same manner, using Not and Or on numeric operands.

See Also

And Operator | AndAlso Operator | Or Operator | OrElse Operator | Not Operator | Xor Operator | TimeSpan Structure | Programming Element Support Changes Summary

Show: