Export (0) Print
Expand All

Boolean Operator for Visual Basic 6.0 Users 

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

In Visual Basic 2005, the And, Or, Not, and Xor operators still evaluate all expressions contributing to their operands. Visual Basic 2005 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.

NoteNote

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 = (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

Community Additions

ADD
Show:
© 2014 Microsoft