PARAMETERS Command

Assigns data passed from a calling program to private variables or arrays.

PARAMETERS Parameter1 [AS type [OF ClassLib]] [, Parameter2 [AS type [OF ClassLib]]]

Parameters

  • ParameterList
    Specifies the variable or array names to which the data is assigned.

    Parameters within ParameterList are separated by commas. There must be at least as many parameters in the PARAMETERS statement as in the DO ... WITH statement. If more variables or arrays are listed in the PARAMETERS statement than are passed by DO ... WITH, the remaining variables or arrays are initialized to false (.F.). You can pass a maximum of 26 parameters.

    PARAMETERS( ) returns the number of parameters that were passed to the most recently executed routine.

  • AS type
    Specifies the data type on which this variable is based.

  • OF ClassLib
    Specifies the class library containing the type description on which the type element of this variable is based.

Remarks

Multiple items in ParameterList are separated by commas. When PARAMETERS is used with DO ... WITH, it must be the first executable statement in the called program, procedure, or user-defined function.

By default, DO ... WITH passes variables and arrays to procedures by reference. When a value is changed in the called procedure, the new value is passed back to the associated variable or array in the calling program. If you want to pass a variable or array to a procedure by value, enclose the variable or array in parentheses in the DO ... WITH parameter list. Any changes made to the parameter in the called procedure are not passed back to the calling program.

Variables are by default passed by reference to a procedure and by value to a user-defined function. Use SET UDFPARMS TO REFERENCE to pass variables to a user-defined function by reference.

The strong typing required by the CodeSense parser in IntelliSense is available only when you create strongly typed object and variable references by using the optional AS clause.

Example

The following example passes parameters to an error-handling routine.

ON ERROR DO errhand WITH ERROR( ), MESSAGE( ), ;
   MESSAGE(1),PROGRAM( ),LINENO( )
USE nodatabase
ON ERROR         && restores system error-handling routine

PROCEDURE errhand
PARAMETERS gnError, gcMess, gnMess1, gcProg, gnLineNo
? 'Error number: ' + LTRIM(STR(gnError))
? 'Error message: ' + gcMess
? 'Line of code with error: ' + gnMess1
? 'Line number of error: '+ LTRIM(STR(gnLineNo))
? 'Program with error: ' + gcProg

See Also

PCOUNT( ) Function | DO | LOCAL | LPARAMETERS | PARAMETERS( ) Function | PRIVATE | PUBLIC | SET UDFPARMS