Custom Order Options - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

Both the Create Designer Legend statement and the Alter Designer Frame statement include an Order clause with the option of specifying a Custom sort order.

Custom id | id : id [ , id | id : id ... ]

Where the following specifies a range of row ids in increasing order (Id2 > Id1):

Id1 : Id2

Reordering a List

The syntax for custom order of legend rows is similar to the Order clause (to reorder layers) in the Set Map statement. It is fairly easy to use when you want to reorder near the beginning of a list, but not so easy when you want to reorder near the end. For instance, if you want to reverse the order of the first three rows you only have to use:

Order Custom 3, 2, 1

You can leave out the rest of the rows. If you have 10 rows and want to switch the last two, you have to list all the ids like this:

Order Custom 1, 2, 3, 4, 5, 6, 7, 8, 10, 9

To make this more compact, use the following syntax:

Order Custom 1:8, 10, 9

Indicating a Range of Values

Use a colon ( : ) to indicate a range of values, such as:

Long form:
Order Custom 2, 5, 6, 7, 8, 9, 10, 1, 3, 4

Short form:
Order Custom 2, 5:10, 1, 3, 4
Order Custom 2, 5:10, 1, 3:4 (same as above but also valid)
Order Custom 2, 5:10, 1 (same as above but also valid)
Long form:
Order Custom 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 11

Short form:
Order Custom 1:10, 12:20, 11

The list of values cannot have duplicates that will cause an error. The following causes an error:

Order Custom 1:5, 8, 4:7

This is because row ids 4 and 5 are duplicates. To see this, expand the syntax as follows (which causes an error):

Order Custom 1, 2, 3, 4, 5, 8, 4, 5, 6, 7

The alternate syntax can be used when creating or altering a legend in the Legend window. For workspaces, the short syntax is used when legends in the Legend window have more than 50 rows with a custom order.