The following table lists the comparison operators provided by Visual Basic.
Operator | Purpose | Example | Result |
---|---|---|---|
= | Equals | A = B | True if A equals B |
<> | Not equals | A <> B | True if A does not equal B |
< | Less than | A < B | True if A is less than B |
<= | Less than or equal to | A <= B | True if A is less than or equal to B |
> | Greater than | A > B | True if A is greater than B |
>= | Greater than or equal to | A >= B | True if A is greater than or equal to B |
Is | Equality of two objects | emp Is mgr | True if emp and mgr refer to the same object |
IsNot | Inequality of two objects | emp IsNot mgr | True if emp and mgr refer to different objects |
TypeOf...Is | Object is of a certain type | TypeOf(obj) True Is Manager | if obj points to a Manager object |
Like | Matches a text pattern | A Like “-#” | True if A contains three digits, a dash, and four digits |
The following table lists characters that have special meanings to the Like operator.
Character(s) | Meaning |
---|---|
? | Matches any single character |
* | Matches any zero or more characters |
# | Matches any single digit |
[characters] | Matches any of the characters between the brackets |
[!characters] | Matches any character not between the brackets |
A-Z | When inside brackets, matches any character in the range A to Z |
The following table lists some useful Like patterns.
Pattern | Meaning |
---|---|
[2-9]##-# | Seven-digit phone number |
[2-9]##-[2-9]##-# | Ten-digit phone number including area code |
1-[2-9]##-[2-9]##-# | Eleven-digit phone number beginning with 1 and area code |
## | Five-digit ZIP code |
##-# | Nine-digit ZIP+4 code |
?*@?*.?* | e-mail address |