Operator Compare

From Xojo Documentation


Used to overload the intrinsic comparison operators, providing custom functionality.


If Operator_Compare is defined, it is called whenever any of the comparison operators are used to compare the Self instance of the class with another instance. The following comparison operators are covered: =, <, >, <=, >=, <>.

Operator_Compare returns an integer whose meaning is as follows: <0 means that Self is less than the passed parameter, 0 means that Self is equal to the passed parameter, and >0 means that Self is greater than the passed parameter.

Sample Code

This example defines a comparison between two Vectors which have been declared with integer properties x and y (See Operator_Add for a description of the Vector class). The function compares the square lengths of the vectors and then reports on which one is longer.

Function Operator_Compare(rhs As Vector) As Integer
Var a, b As Integer
a = Self.x ^ 2 + Self.y ^ 2
b = rhs.x ^ 2 + rhs.y ^ 2
If a > b Then Return 1
If a = b Then Return 0
If a < b Then Return -1
End Function

See Also

=, <, >, <=, >=, <> operators.