CoreClasses Xojo Plugin

IVariantComparer.Compare Method (console safe)

Implement this method to have a valid class that implements the IVariantComparer Interface.

The implemented method should return:
-1 if variant a < variant b
1 if variant a > variant b
0 if variant a = variant b

So what needs to be done is
if(variant a < variant b) then
return -1
elseif(variant a > variant b) then
return 1
else
return 0
end if

Compare(
   a as Variant,
   b as Variant) as Integer

Parameters

a
One of the variant to compare.
b
The other variant to compare.

Returns

Integer
-1 if variant a < variant b
1 if variant a > variant b
0 if variant a = variant b

Remarks

How you evaluate which variant is bigger is up to you and depends entierly on what kind of variant you are comparing and what you want to acomplish. To compare the variant you will need to typecast the variant to their actual types.

Speed optimizations for sorting:
If you know you will only be doing ascending sort then you can speed optimize the comparer method by only evaluating to -1 and 0 like:

if(variant a < variant b) then
return -1
else
return 0

Same thing goes for if you know you will only be doing descending sort then you can speed optimize the comparer method by only evaluating to 1
and 0 like:

if(variant a > variant b) then
return 1
else
return 0

See Also

IVariantComparer Interface