PRB: "Variable Not Found" Error Occurs with Filter Expression

ID: Q119898

The information in this article applies to:

SYMPTOMS

When you are performing a SEEK, a LOCATE, or a FIND, the following error message occurs:

   Variable '<variable name>' not found.

CAUSE

A filter expression has been set, and it uses the variable that can no longer be found. When the filter expression is reevaluated during the search, FoxPro reports that the variable cannot be found.

RESOLUTION

While every case is likely to be different, the problem illustrated below could be resolved in one of the following ways:

1. Make the variable used in the filter expression PUBLIC.

   NOTE: Verify that the code does not contain a PRIVATE command that makes
   the variable in question private.

   -or-

2. Change the SetFilter procedure to the following:

      PROCEDURE SetFilter
      PARAMETER x
      cExpr = 'state ="'+ x + '"'
      SET FILTER TO &cExpr

In the second case, the use of macro substitution eliminates the dependency of the filter upon the variable.

MORE INFORMATION

Steps to Reproduce Behavior

1. Enter the following code in a program:

      USE customer
      INDEX ON cno TAG cno

      DO SetFilter WITH 'CA'
      SEEK 'A2695'

      PROCEDURE SetFilter
      PARAMETER x
      SET FILTER TO state=x

2. Run the program.

In the code above, the error occurs because the variable used in the filter expression loses its scope when the SetFilter procedure terminates. FoxPro senses this and clears the filter because it is no longer valid.

Additional reference words: FoxUnix FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.50c 2.60 2.60a KBCategory: kbprg kberrmsg kbprb KBSubcategory: FxprgMacrosub

Last Reviewed: June 27, 1995