Method

Operator_Compare


Description

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

Notes

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

Compatibility

All project types on all supported operating systems.

See also

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