5.5. Comparison OperatorsThere 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 to form other comparison operators. The general syntax is: result = expression1 <operator> expression2 The result is a Boolean value of TRue or False . The following list indicates the condition required with each VB comparison operator to return a value of TRue .
Comparison operators can be used with both numeric and string expressions. If one expression is numeric and the other is a string, the string is first converted to a number of type
Double
(nonnumeric strings throw an exception). If both
expression1
and
expression2
are strings, the "greatest" string is the one that appears second in
New in 2005 . There are two "hidden" operators in Visual Basic: IsTrue( arg ) and IsFalse( arg ) . They return a Boolean value that indicates whether the supplied argument is true or False , respectively. You cannot use them directly in your code, but they do exist, beginning in the 2005 release of Visual Basic, to support operator overloading. This is covered in the "Operator Overloading" section later in this chapter. 5.5.1. The Like Operator
The
Like
operator is used to match a string against a pattern. It
If (testString Like "[A-Z]#") Then matches a capital letter followed by a digit.
For details on the use of this operator, including special
|
5.6. Object OperatorsVisual Basic includes five operators that return results based on an operand's object properties.
|