See Also Example
Used to perform logical negation on an expression.
result = Not expr
The following table illustrates how result is determined:
If expr is Then result is
In addition, the Not operator inverts the bit values of any variable and sets the corresponding bit in result according to the following truth table:
Bit in expr Bit in result
If an integer variable has the value 0 (False), the variable becomes -1 (True); if it has the value -1, it becomes 0.
Not Operator Example
The example displays a message that depends on the value of variables A and B, assuming neither variable is a Null. If A = 10 and B = 8, the Not expression evaluates True because A is not equal to B. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim A, B, Msg ' Declare variables.
A = 10: B = 8 ' Assign values.
If Not A = B Then ' Evaluate expression.
Msg = "A and B aren't equal."
Msg = "A and B are equal."
MsgBox Msg ' Display results.