SET UDFPARMS Command 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 is unchanged ***
@ 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 is changed ***
@ 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 ***