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:

This would be written as follows in VBA:

Alternatively, the above 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 used by C, C++, Java, and JavaScript:

0 0

Post a comment

  • Receive news updates via email from this site