Comparison Operators
There are three main comparison operators:
<
(less than),
>
(greater than), and
= (equal
to). They can be used individually, or any two operators can be
combined with each other. Their general syntax is
result = expression1 operator
expression2
The resulting expression is True
(-1),
False
(0), or Null
. A
Null
results only if either
expression1
or
expression2
itself is
Null
.
What follows is a list of all the comparison operators supported by
VBA, as well as an explanation of the condition required for the
comparison to result in True
:
-
>
expression1
is greater than and not equal toexpression2
-
<
expression1
less than and not equal toexpression2
-
<>
or><
expression1
not equal toexpression2
(less than or greater than)-
>=
or=>
expression1
greater than or equal toexpression2
-
<=
or=<
expression1
less than or equal toexpression2
-
=
expression1
equal toexpression2
Comparison operators can be used with both numeric and string
variables. However, if one expression is numeric and the other is a
string, the numeric expression will always be “less than”
the string expression. If both expression1
and expression2
are strings, the
“greatest” string is the one that is the longest. If the
strings are of equal length, the comparison is case-sensitive.
(Lowercase letters are “greater” than their uppercase
counterparts.)
The Is operator
While not strictly a comparison operator, the
Is
operator determines whether two object reference variables refer to the same ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.