PRB: INDEX ON Expression Var Causes Error and Doesn't Evaluate

ID: Q125656

The information in this article applies to:

SYMPTOMS

After using macro substitution or a name expression to change an index filter in an INDEX ON command, you receive this error:

   Variable '<variable value>' not found.

CAUSE

FoxPro evaluates the macro substitution or a name expression as a variable name instead of a literal value. A variable used in an INDEX ON command as an Index Filter cannot be evaluated to its underlying value in the resulting index expression when you use macro substitution or a name expression.

STATUS

This behavior is by design. The variable used in the Index Filter must always be present before using that index. Note that macro substitution or name expression will function as expected to the left of the equal sign of the INDEX ON command.

MORE INFORMATION

Steps to Reproduce Behavior

1. Create and run a program containing this code:

   USE customer
   cityn="Seattle"
   INDEX ON city TO test FOR city=cityn

   This program will create an .IDX file named test with an index on the
   field named city and an index filter of city=cityn.

2. Use macro substitution or name expression to change the INDEX ON
   expression to this:

   INDEX ON city TO test FOR city=&cityn

   -or-

   INDEX ON city TO test FOR city=EVAL(cityn)

   You might hope the result would be an index filter of city="Seattle".
   But the following error message is generated:

   Variable 'Seattle' not found.

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbprg kbprb KBSubcategory: FxprgMacrosub

Last Reviewed: July 26, 1995