[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
+---------------------------------+
|          SET UDFPARMS           |
+---------------------------------+
SET UDFPARMS TO VALUE | REFERENCE

-----------------------------------
Controls how parameters are passed to user-defined function (UDF).
-----------------------------------

By default, variables are passed to user-defined functions by value.
(Variables are always passed to procedures by reference unless you
specifically pass them by value by enclosing them in parentheses.)  When
a variable is passed by value, the variable's value may be changed by
procedure or UDF, but variable's original value in calling program is
not changed.

When variable is passed by reference and UDF changes value of  passed
variable, variable's original value in the calling program is also
changed.

The following example illustrates the difference in variable passing by
value as opposed to reference.

+---------------------------------+
|             Examples            |
+---------------------------------+
*** Pass memory variable by value ***

CLEAR
SET TALK OFF
WAIT 'Press a key to pass by value' WINDOW
SET UDFPARMS TO VALUE
STORE 1 TO X
*** The value of x is unchanged ***
@ 2,2 SAY 'UDF value:  ' + STR(plusone(X))
@ 4,2 SAY 'Value of X: ' + STR(X)

*** Pass memory variable by reference ***

WAIT 'Press a key to pass by reference' WINDOW
CLEAR
SET UDFPARMS TO REFERENCE
STORE 1 TO X
*** The value of x is changed ***
@ 2,2 SAY 'UDF value:  ' + STR(plusone(X))
@ 4,2 SAY 'Value of X: ' + STR(X)

*** This is a UDF that adds one to a number ***

FUNCTION plusone
PARAMETER Z
Z = Z + 1
RETURN Z

*** End of UDF ***

You may force parameters to be passed by value or reference, ignoring
setting of UDFPARMS.  To force a variable to be passed by value, enclose
variable in parentheses.  To force a variable to be passed by reference,
preface the variable with an AT symbol @.

Here is the above example with variables passed by value and reference
through the use of parentheses and @ respectively:

*** Pass memory variable by value ***

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

*** Pass memory variable by reference ***

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

*** This is a UDF that adds one to a number ***

FUNCTION plusone
PARAMETER Z
Z = Z + 1
RETURN Z

*** End of UDF ***

Entire arrays may be passed to a procedure or UDF.  If UDFPARMS is SET
TO REFERENCE or the array name is prefaced with @, the entire array is
passed.  If UDFPARMS is SET TO VALUE or the array name is surrounded by
parentheses, first element of the array is passed by value.  Array
elements are always passed by value.

-----------------------------------

See Also:  PARAMETERS, PARAMETERS(), PROCEDURE, USER-DEFINED FUNCTIONS
(UDFs)

-----------------------------------

See Also: PARAMETERS PARAMETERS() PROCEDURE
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson