I’m looking at the documentation on variants and it says
But what happens when both operands are variants?
Essentially I want if the variants are strings, to do a string compare but if they’re integers or doubles I want it to instead compare their values.
So far I’m just trying to case it out
if str(v.DoubleValue) = v.StringValue and str(v2.DoubleValue) = v2.StringValue // then Compare their double values
elseif str(v.IntegerValue) = v.StringValue and str(v2.IntegerValue) = v2.StringValue // then Compare their integer values
Is this necessary?
I also see that there’s an Operator_Compare method on the variant object but no examples of how to utilize this.
I’m trying to do a merge sort on an array of variants essentially, but I need to get the Compare working correctly.
I have a helper method that will turn arrays of primitives into arrays of (variant) objects so that they can be used with these extension methods, but implementing the OrderBy is difficult due to the fact that you don’t know what original type the variants came from and whether to sort them based on Value or String Order.
I wasn’t sure if there a good way to handle this or what the default comparing of variants would do.
Could you refactor to wrap the Variant array into a Class rather than working with a raw Variant Array.
With a class you can add a property to track the original array type which the helper methods would set. Then orderBy() could check that. And your extension methods could be moved to the class.
Class FlexiList
list() As Variant
sourceType As something
End Class