How to: Set Controlling Indexes

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.

NoteNote

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

  1. Open the browse window for your table.

  2. On the Table menu, choose Properties.

  3. In the Index order box of the Work Area Properties dialog box, select the index you want to use.

  4. Choose OK.

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.

      NoteTip

      When opening a table using the USE command, including the ORDER clause in performs the same function as SET ORDER.

      You do not need to use SET ORDER for running queries.

    • To set the controlling index for the currently open table, use the SET INDEX command.

      NoteTip

      When opening a table using the USE command, including the INDEX clause in performs the same function as SET INDEX.

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:

 CopyCode imageCopy Code
OPEN DATABASE (HOME(2) + 'Data\TestData')
SET ORDER TO Country
BROWSE

For more information, see SET ORDER Command, SET INDEX Command, USE Command, and BROWSE Command.

See Also


© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic