BUG: Variable Passed/Declared as PRIVATE in UDF Not Returned

ID: Q125789

The information in this article applies to:

  • Microsoft FoxPro for MS-DOS, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a

SYMPTOMS

Under the following conditions, the PARAMETER variable will take on the value of the local variable in the UDF when the READ is issued, and the value of the passed variable (x) is never changed in the calling program.

This problem occurs if the following steps are taken:

1. A variable is passed by reference to a UDF or PROCEDURE such as

   myfunc(x).

2. The passed variable is received in the UDF or PROCEDURE PARAMETER
   statement with a different variable name such as PARAMETER y.

3. A variable with the passed name is declared locally in the UDF or
   PROCEDURE such as x=<value>.

4. A READ is executed against the PARAMETER variable.

WORKAROUND

Adopt a naming scheme that avoids the problem. For example:

  • Do not use the passed variable name in the UDF.

    -or-

  • Let the PARAMETER variable have the same name as the passed variable.

    -or-

  • Do not issue a READ against the PARAMETER variable.

STATUS

Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Behavior

Run the following code, noting the comments as it is stepped through in the Trace Window. Enter 2 into the GET and note that it is not passed back to x in the calling program.

   CLEAR
   SET UDFPARMS TO REFERENCE
   ACTIVATE WINDOW DEBUG      && put X and Y in it.
   SET STEP ON
   PUBLIC x

   x=1
   =getx(x)
   @ 11,5 SAY x             && does not change!
   RELEASE WINDOW TRACE
   RELEASE WINDOW DEBUG
   SET UDFPARMS TO VALUE    && reset to default

   FUNCTION getx
   PARAMETER y
   PRIVATE x
   x=4
   @ 5, 5 GET y    && Y contains the correct passed value, 1

   @ 7,5 SAY y

   @ 9,5 SAY x     && local X contains 4

   * observe that the GET Y takes on the value of the
   * local X as soon as the READ is executed.
   * Enter a new value in GET Y and
   * observe that the value of Y does not change,
   * only the local X value changes
   READ

Notes

Any of the following will allow the value of y to return to x properly:

  • Issue the READ against another variable <varname> and set y=<varname>.

    -or-

  • Use x as the PARAMETER variable in the UDF.

    -or-

  • Do not use the variable x in the UDF at all.

Additional reference words: FoxWin FoxDos buglist2.50 buglist2.50a buglist2.50b buglist2.60 buglist2.60a 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbprg kbbuglist KBSubcategory: FxprgGeneral


Last Reviewed: June 27, 1995
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.