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

Last reviewed: June 28, 1995
Article ID: Q116032
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for Macintosh, version 2.5b, 2.5c

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 28, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.