Understanding automation : How is automation coding structured? : Using logical and bitwise operators |
In VBA, logical operations are performed by using the keywords And
, Not
, Or
, Xor
, Imp
, and Eqv
, which perform the logical operations AND, NOT, OR, Exclusive-OR, logical implication, and logical equivalence (respectively). These operators also perform Boolean comparisons.
The following code shows a comparison written in C or a similar language:
if( ( a && b ) || ( c && d ) ) |
This example would be written as follows in VBA:
If ( a And b ) Or ( c And d ) Then |
Alternatively, the preceding VBA code could be written in the following full long-hand form:
If ( a And b = True ) Or ( c And d = True ) = True Then |
The following table provides a comparison of the four common VBA logical and bitwise operators, and the C-style logical and bitwise operators that are used by C, C++, Java, and JavaScript.
Copyright 2013 Corel Corporation. All rights reserved.