Microsoft KB Archive/125789

{| = BUG: Variable Passed/Declared as PRIVATE in UDF Not Returned =
 * width="100%"|

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=. 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.

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