Not (operator)

Syntax Not expression
Description Returns either a logical or binary negation of expression.
Comments The result is determined as shown in the following table:
If the expression is Then the result is
TRUE FALSE
FALSE TRUE
NULL NULL
Any numeric type A binary negation of the number. If the number is an Integer, then an Integer is returned. Otherwise, the expression is first converted to a Long, then a binary negation is performed, returning a Long.
empty Treated as a Long value 0.
Example This example demonstrates the use of the Not operator in comparing logical expressions and for switching a True/False toggle variable.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
  a = False
  b = True
  If (Not a and b) Then msg1 = "a = False, b = True" & crlf
                           
  toggle% = True
  msg1 = msg1 & "toggle% is now " & CBool(toggle%) & crlf
  toggle% = Not toggle%
  msg1 = msg1 & "toggle% is now " & CBool(toggle%) & crlf
  toggle% = Not toggle%
  msg1 = msg1 & "toggle% is now " & CBool(toggle%)
  MsgBox msg1
End Sub
See Also Boolean (data type); Comparison Operators (topic).