setparameter
NUMBER
,
VALUE

The setparameter statement is used to transfer data from a subroutine back to the main procedure that called it.


Parameters

This statement has two parameters:

number – is a number specifying what parameter you want to set. All parameters are numbered, starting with 1 (1,2,3,4, etc.). A parameter may only be modified if it is a field or variable. If a parameter is a more complex formula, it cannot be modified. For example if the parameter is Name or BookCount it can be modified. If the parameter is upper(Name), "Frank", or City+", "+State it cannot be modified. If you attempt to modify a parameter that is not a simple field or variable, an error will occur (which can be trapped with if error, see Error Handling).

value – is the value to be stored in the parameter.


Description

The setparameter statement is used to transfer data from a subroutine back to the main procedure that called it. When a procedure uses the call statement to activate a subroutine, it can pass one or more values to the subroutine. These values are called parameters. If a parameter is in a field or variable, the subroutine can use the setparameter statement to modify the value and pass it back to the original procedure.

The procedure below (called GetNumber) assumes that two parameters will be passed to it, and it modifies the second parameter.

// Subroutine: GetNumber
//
// This subroutine expects two parameters:
// (1) prompt text
// (2) new value (a number)
//
// Example:
// call GetNumber,"How many weeks",WeekCount
//
local temptext
temptext=str( parameter(2))
gettext parameter(1),temptext
setparameter 2,val(temptext)

The procedure below uses the GetNumber procedure to ask the user to enter a number. It then uses that number (which is placed in the addCount variable, the second parameter to the call statement) to determine how many records to add to the database. Notice that the addCount value must be converted to a number after it is returned by the subroutine.

local addCount
addCount=1
call GetNumber,"Add how many records?",addCount
loopwhile addCount>0
    addrecord
    addCount=addCount-1
endloop

Error Messages

Parameter does not exist – The requested parameter was not supplied by the calling procedure.

Cannot set parameter value because parameter N is not a field or variable – The requested parameter is not a field or variable name, rather it is something more complex. The setparameter statement can only be used with simple field or variable names.

Cannot set parameter N value. – The data supplied cannot be stored into the specified field or variable. This could mean that there is no field or variable with the specified name. Or, if a field is specified, it could mean that the data to be stored is not compatible with the field, for example, you cannot store text into a numeric field.


See Also


History

VersionStatusNotes
10.0No ChangeCarried over from Panorama 6.0