setparameter
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

- assign -- assigns a value to a field or variable.
- assignfield -- performs an assignment, much like an equals sign or the assign statement. However, the *assignfield* statement only performs the assignment to a database field, not to any variable.
- assignfieldwithsideeffects -- performs an assignment, much like an equals sign or the assign statement. However, the *assignfieldwithsideeffects* statement only performs the assignment to a database field, not to any variable. After performing the assignment, it will run any side effects associated with the field, including formulas and code associated with the field.
- assignfileglobal -- performs an assignment, much like an equals sign or the assign statement. However, the *assignfileglobal* statement only performs the assignment to a fileglobal variable.
- assignglobal -- performs an assignment, much like an equals sign or the assign statement. However, the *assignglobal* statement only performs the assignment to a global variable.
- assignlocal -- performs an assignment, much like an equals sign or the assign statement. However, the *assignlocal* statement only performs the assignment to a local variable.
- assignwindowglobal -- performs an assignment, much like an equals sign or the assign statement. However, the *assignwindowglobal* statement only performs the assignment to a windowglobal variable.
- call -- allows a procedure to call a separate procedure within the current database as a subroutine.
- call( -- allows a procedure to be called as a subroutine within a formula and return a result.
- calledby( -- returns true if this function is in code called by the specified database, the specified procedure, or both.
- callingdatabase( -- returns the name of the database that called this procedure as a subroutine, if any.
- callingprocedure( -- returns the name of the procedure that called this procedure as a subroutine, if any.
- callwithin -- allows a procedure to call a mini-procedure within a separate procedure within the current database as a subroutine.
- callwithin( -- allows a "mini-procedure" to be called as a subroutine within a formula and return a result.
- callwithindatabase( -- returns true if the current procedure was called by another procedure in the same database, false if it was called by a procedure in another database.
- define -- performs an assignment, much like an equals sign or the assign statement. However, the *define* statement only performs the assignment if the variable is currently undefined. If the variable already has a value, the *define* statement leaves it alone. The *define* statement is especially useful for initializing permanent variables.
- execute -- allows a procedure to call a sequence of statements within the current procedure as a "mini-subroutine".
- execute( -- allows a formula to execute a sequence of statements and return a result.
- executeasap -- executes the specified code at the first possible opportunity, non-atomically.
- executecatcherrors -- is the same as the execute statement, except for the fact that if an error occurs while running, it can be trapped by an if error statement immediately following the executecatcherrors statement.
- executelocal -- is the same as the execute statement, but it shares local variables with the procedure that called it.
- farcall -- allows a procedure to call a separate procedure within a different database as a subroutine.
- farcallwithin -- allows a procedure to call a mini-procedure within a separate procedure in a different database as a subroutine.
- getproceduretext( -- gets the contents (source code) of a procedure.
- info("parameters") -- returns the number of parameters passed to a subroutine.
- info("procedurestack") -- returns the contents of Panorama's procedure call stack.
- let -- creates a local variable and assigns a value to it.
- letfileglobal -- creates a fileglobal variable and assigns a value to it.
- letglobal -- creates a global variable and assigns a value to it.
- letpermanent -- creates a permanent variable and assigns a value to it.
- letservervariable -- creates a server variable and assigns a value to it.
- letwindowglobal -- creates a windowglobal variable and assigns a value to it.
- parameter( -- is used to transfer data between a main procedure and a subroutine.
- parameterentity( -- returns the entity (field or variable) associated with a subroutine parameter, if any.
- return -- ends a subroutine.
- returnerror -- passes an error back to the current subroutines calling procedure.
- set -- performs an assignment, much like an equals sign or the assign statement. However, the destination of the assignment can be calculated on the fly.
- setfield -- performs an assignment, much like an equals sign or the assign statement. However, the destination field of the assignment can be calculated on the fly.
- setglobal -- sets a value into a global variable. The name of the global variable is calculated on the fly.
- setlocal -- sets a value into a local variable. The name of the local variable is calculated on the fly.
- setlocalsfromdictionary -- converts a dictionary into a collection of local variables. The names and values of the local variables will be derived from the dictionary contents.
- shortcall -- allows a procedure to call a sequence of statements within the current procedure as a "mini-subroutine".

History

Version | Status | Notes
10.0 | No Change | Carried over from Panorama 6.0