Boolean Operator for Visual Basic 6.0 Users

Visual Basic 2008 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 2008

In Visual Basic 2008, the And, Or, Not, and Xor operators still evaluate all expressions contributing to their operands. Visual Basic 2008 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 logical evaluations; for bitwise evaluations use Not and XOr as shown in the following example:

Result = Not (A XOr B) 'Same as A Eqv B
                       '(True unless A and B are not both True or False

You can replace the logical Imp operator with an expression using the Not and Or operators, as shown in the following example:

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

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

See Also

Concepts

Programming Element Support Changes Summary

Reference

And Operator (Visual Basic)

AndAlso Operator

Or Operator (Visual Basic)

OrElse Operator

Not Operator (Visual Basic)

Xor Operator (Visual Basic)

TimeSpan