Microsoft KB Archive/116032

{| = PRB: UDF in SET FILTER TO Error: Invalid Subscript Reference =
 * width="100%"|

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
 * }