Visual Basic supplies a set of six relational operators to compare the magnitudes of two data values and comparisons can be made with numeric or string values, with a Boolean value returned from the comparison.
A D V E R T I S E M E N T
The following table summarizes these relational operators
Operator
Use
=
Tests whether two values are equal.
<>
Tests whether two values are not equal.
<
Tests whether the first value is less than the second value.
>
Tests whether the first value is greater than the second value.
<=
Tests whether the first value is less than or equal to the second
value.
>=
Tests whether the first value is greater than or equal to the second
value.
In the following example,the Boolean value True is assigned to Result2 and the Boolean value False is assigned to variable Result1.Value1 is not equal to Value2; rather, Value1 is less than Value2.
Dim Value1 As Decimal = 10
Dim Value2 As Decimal = 20
Dim Result1 As Boolean
Dim Result2 As Boolean
Relational tests can be combined to test multiple conditions at the same time and the logical operators AND, OR, NOT, and Xor are used as conjunctions between multiple relational tests.
In the following example, all of the complex relational tests are True and notice in the third relational test that parentheses are used, just as in composing arithmetic expressions, to control the order in which tests are made.
Dim Value1 As Decimal = 10
Dim Value2 As Decimal = 20
Dim Value3 As Decimal = -5
Dim Result1 As Boolean
Dim Result2 As Boolean
Dim Result3 As Boolean
Result1 = Value1 < Value2 AND Value1 > Value3
Result2 = Value1 > Value2 OR Value1 > Value3
Result3 = Value1 < Value2 AND (Value1 > Value3 OR Value2 < Value3)