CorArray: SortEx

SortEx

Sorts an array, or subportion, given a startindex and length. An optionally supplied comparer object can be used to compare special elements, such as userdefined values.



 Public Sub SortEx(
	  ByRef Arr As Variant,
	  ByVal Index As Long,
	  ByVal Length As Long,
	  Optional ByRef Comparer As Variant )

Parameters

Arr
[ByRef] Variant. The array to sort.
Index
[ByVal] Long. The starting index in the array to start sorting.
Length
[ByVal] Long. The number of elements to be sorted.
Comparer
[ByRef] Optional. Variant. An IComparer object or address of a comparer callback function.

Remarks

The Comparer parameter can be an IComparer interface or a callback address to a compare function using the AddressOf method. The callback method signature is defined as follows:

 Public Function SortCallback(ByRef x As <Type>, ByRef y As <Type>) As Long
     ' return less than zero if x is less than y.
     ' return greater than zero if x is greater than y.
     ' return zero if x equals y.
 End Function
 
The <Type> the type of element of the array. If the array is an array of Variants, then <Type> would be a Variant, not any specific sub-type within the variant elements of the array.

See Also

Project CorLib Overview

Class CorArray Overview

IComparer

Sort

SortKey

SortKeyEx