Collection.SortBy Method
The SortBy method is useful to sort a collection of items using
one or multiple sort keys. collection.SortBy(strSortKey)
Example:
The following example displays a list of children sorted by first name. Report.Write i.children.SortBy("name.first").ToHtmlHyperlinksNN
Usage:
You can use the SortBy as method or as a property.
Dim collChildren
Set collChildren = i.children.GetCollection
Set collChildren = collChildren.Reverse
collChildren.Reverse
collChildren.SortBy("name.middle, age")
Report.Write3Br "Children: ", collChildren.SortBy("name").ToHtmlHyperlinksNN
Report.Write3Br "Children: ", i.children.Reverse.ToHtmlHyperlinksNN
Multiple Sort Keys:
You can sort a collection by multiple keys. Just specify the keys you
want to sort separated by a comma. For instance, if you want a list of all
the individuals sorted by last name, first name and middle name, you would write
the following code. Dim collectionIndividuals
Set collectionIndividuals = individuals.SortBy("name.last, name.first, name.middle")
Sort in Descending Order:
You can sort a given key in a descending order, just the minus sign in front
of the sort key. For instance, if you want the first names sorted in
reverse order you would write the following. Dim collectionIndividuals
Set collectionIndividuals = individuals.SortBy("name.last, -name.first, name.middle")
In the future, there will be more powerful sorting options. If you need
fancy sorting, use the DataSorter .
|