PRB: UDF in SET FILTER TO Error: Invalid Subscript Reference

ID: Q116032

The information in this article applies to:

SYMPTOMS

Using a user-defined function (UDF) in a SET FILTER expression causes the error message "Invalid Subscript Reference" to occur.

CAUSE

FoxPro does not allow a UDF to be used in a SET FILTER expression.

RESOLUTION

To avoid this problem, do not use a UDF in a SET FILTER expression. If the logic in the UDF is too complex to be incorporated into the SET FILTER expression, use a different approach to process a subset of the records, such as the SELECT-SQL command or the SCAN command.

STATUS

This behavior is by design.

MORE INFORMATION

In dBASE IV, you can use a UDF in a SET FILTER expression. The UDF will function as expected, and no error messages will be returned. In FoxPro, however, this situation will result in the error message "Invalid Subscript Reference." This behavior is not affected by the setting of SET COMPATIBLE.

Steps to Reproduce Problem

The following code produces a "Invalid Subscript Reference" error message when executed in FoxPro. When this code is executed in dBASE IV, no errors will occur. The LIST command will produce one record, with the value of "BB".

   CREATE TABLE test (one C(2))
   INSERT INTO test (one) VALUES ("AA")
   INSERT INTO test (one) VALUES ("BB")
   INSERT INTO test (one) VALUES ("CC")
   INSERT INTO test (one) VALUES ("DD")

   SET FILTER TO myudf()

   LIST

   FUNCTION myudf
     retval = .F.
     IF one = "BB"
        retval = .T.
     ENDIF
   RETURN(retval)

Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.60 2.50c errmsg err msg KBCategory: kbprg kberrmsg kbprb KBSubcategory: FxinteropDbase

Last Reviewed: June 28, 1995