A table can have many index files open simultaneously; however, only one master, or controlling, index file or tag specifies the order in which Visual FoxPro displays or accesses the table. Also, certain commands, such as the SEEK command, use the controlling index file or tag to search for records.
|You cannot select binary indexes as controlling indexes. Visual FoxPro does not support the SET ORDER command when setting to a binary index tag. If you attempt to set order to a binary tag, Visual FoxPro generates an error, and the current order remains at its prior setting. Records in the table are displayed and accessed in record number order and not in an indexed order. Therefore, Visual FoxPro does not support SEEK operations for binary indexes.|
After you create one or more indexes for a table, you need to assign a controlling index for organizing records in your table. You can designate an index tag in a compound index (.cdx) file or a standalone index (.idx) file as the controlling index tag or file. When changes are made to the table, all open .idx and .cdx files are updated.
You can select a controlling index using the Visual FoxPro IDE or language.
To designate a controlling index
Open the browse window for your table.
On the Table menu, choose Properties.
In the Index order box of the Work Area Properties dialog box, select the index you want to use.
The browse window displays records in the order that the index specifies.
To set controlling indexes programmatically
Choose one of the following:
To set the controlling index for a table, use the SET ORDER command.
You do not need to use SET ORDER for running queries.
Tip: When opening a table using the USE command, including the ORDER clause in performs the same function as SET ORDER.
To set the controlling index for the currently open table, use the SET INDEX command.
Tip: When opening a table using the USE command, including the INDEX clause in performs the same function as SET INDEX.
- To set the controlling index for a table, use the SET ORDER command.
For example, suppose an index with the tag name Country is created for the Customer table in the Visual FoxPro sample database, TestData. The following code uses the SET ORDER command to specify Country as the controlling index for displaying the records in the table when you open the table. The BROWSE command opens a browse window and displays the records by country name:
OPEN DATABASE (HOME(2) + 'Data\TestData') SET ORDER TO Country BROWSE