The direction is either ascending or descending. If you don't specify a direction, the sort is ascending.

The sortType is one of text, numeric, or dateTime. If you don't specify a sortType, the sort is by text.

The sortKey is an expression that evaluates to a value for each line or item in the container. If the sortKey contains a chunk expression, the keyword each indicates that the chunk expression is evaluated for each line or item. If you don't specify a sortKey, the entire line (or item) is used as the sortKey.

Comments:

If you don't specify lines or items, the lines of the container are sorted.

The sort international form is like sort text, except that it sorts accented characters together with their unaccented counterparts. For example, "" sorts between "e" and "f", rather than at the end of the alphabet as it would using the sort text form.

The each keyword, when used in the sortKey, specifies the entire line or item. You can use the each keyword in an expression, as a placeholder for the current line or item. For example, this statement sorts the lines of a variable by the third word of each line:

sort lines of myVariable by word 3 of each

You can use the each keyword in any expression, not just chunk expressions.

The sort text form sorts by the ASCII value of each character. The sort numeric form sorts by number. Use this form if the sortKey consists of numbers. The sort dateTime form treats the sortKey as a date and/or time.

The sort container command is a stable sort. This means that if the sortKey for two items or lines is the same, sorting does not change their order, so you can do two successive sorts to create subcategories within the major sort categories.

Tip: To create a custom sort order, use the eachkeyword to pass each line or item to a custom function. The valuereturned by the function is used as the sort key for that line or item. Note that it is not currently possible to debug custom sort functions, and doing so could make the IDE unstable. It is recommended to use logging messages instead.

Lessons

User Comments

Oliver Kenyon

Apr 24, 2009

The ability to use custom sort functions makes sorting in Revolution quite powerful. For example if you want to sort a list of prices without preprocessing the list something like this could be done: