Partager via


SET UDFPARMS Command

Specifies whether Visual FoxPro passes variables by value or by reference to parameters in procedures and user-defined functions (UDFs).

SET UDFPARMS TO VALUE | REFERENCE

Parameters

  • TO VALUE
    Pass variables to parameters by value. When passing variables by value, the procedure or function can change the value in the variable; however, the original value of the variable in the calling program does not change. (Default)

    Note

    Using SET UDFPARMS TO VALUE does not affect the WITH clause in the DO command, which, by default, passes arguments to parameters by reference.

  • TO REFERENCE
    Pass variables to parameters by reference. When passing variables by reference, the procedure or function can change the value in the variable, which changes the original value of the variable in the calling program.

Remarks

Regardless of the setting of SET UDFPARMS, you can force passing of variables by value or reference. For more information, see How to: Pass Parameters by Reference and How to: Pass Parameters by Value.

Example

The following example illustrates the difference between passing variables by value and by reference.

** Pass variable by value. ** CLEAR SET TALK OFF WAIT 'Press a key to pass by value' WINDOW SET UDFPARMS TO VALUE STORE 1 TO gnX

** The value of gnX does not change. ** @ 2,2 SAY 'UDF value: ' + STR(plusone(gnX)) @ 4,2 SAY 'Value of gnX: ' + STR(gnX)

** Pass variable by reference ** WAIT 'Press a key to pass by reference' WINDOW CLEAR SET UDFPARMS TO REFERENCE STORE 1 TO gnX ** The value of gnX changes. ** @ 2,2 SAY 'UDF value: ' + STR(plusone(gnX)) @ 4,2 SAY 'Value of X: ' + STR(gnX) SET UDFPARMS TO VALUE

** This is a UDF that adds one to a number ** FUNCTION plusone PARAMETER gnZ gnZ = gnZ + 1 RETURN gnZ ** End of UDF **

The following is the above example with variables passed by value and reference through the use of parentheses and @, respectively.

** Pass variable by value ** CLEAR SET TALK OFF WAIT 'Press a key to pass by value' WINDOW STORE 1 TO gnX @ 2,2 SAY 'UDF value: ' + STR(plusone((gnX))) @ 4,2 SAY 'Value of gnX: ' + STR(gnX)

** Pass variable by reference ** WAIT 'Press a key to pass by reference' WINDOW CLEAR STORE 1 TO gnX @ 2,2 SAY 'UDF value: ' + STR(plusone(@gnX)) @ 4,2 SAY 'Value of gnX: ' + STR(gnX)

** This is a UDF that adds one to a number ** FUNCTION plusone PARAMETER gnZ gnZ = gnZ + 1 RETURN gnZ ** End of UDF **

See Also

Concepts

Passing Data to Parameters

Parameters in Procedures and Functions

Reference

SET Command Overview

Other Resources

Commands (Visual FoxPro)