assign(
VALUE
,
FIELDVARIABLE
)

The assign( function assigns a value to a field or variable, also returning the value.

Parameters

This function has two parameters:

value – the value to be stored in the field or variable. This value is also returned as the result of the function.

fieldvariable – the name of the field or variable to store the value into. The field or variable must already exist and must be enclosed in quotes.

Description

The assign( function is different from almost every other Panorama function. Instead of calculating a new value based on its parameters, the assign( function allows you to assign the result of a partial formula to a field or variable. This is called a side effect because this assignment is in addition to the normal operation of the formula that contains the assign( function, or multiple assign( functions.

Let’s look at some examples to illustrate the operation of this function. For example, consider the equation below, which might be part of a procedure. In this example, both A and B will be assigned the value X+Y.

``````B=assign(X+Y,"A")
``````

When using the assign( function, it’s important to keep in mind that this function also produces a value - the value calculated by the value parameter. For example, in the example above B is also assigned the value X+Y. If you forget that the assign( function produces a value you may encounter unexpected error messages or even accidentally overwrite data.

The previous example illustrated the operation of the assign( function, but it wasn’t really very useful. Here is a more interesting example. This example quickly scans a field and finds the largest value. The output of the arraybuild (the variable x), is simply ignored. The real result is the variable biggest, which is calculated as a side effect. At the end of the procedure this variable will contain the largest value in the current field.

``````local biggest,x
biggest=«Shoe Size»
arraybuild  x,cr(),"",assign( ?( biggest>«Shoe Size»,biggest,«Shoe Size»),"biggest")
message biggest
``````

The assign( function is very useful for formulas that display text in form objects. In these objects the assign( function can be used for intermediate values that need to be used over and over. Of course when you use the assign( function this way you have to keep in mind the order of expression evaluation. You must make sure that the assign( function is evaluated before the destination is used. Here is an example where the customer name is assigned to a variable named tempCustomerName (which must be created with a global or fileglobal statement before this formula is displayed), then used in several locations in the text without having to re-do the lookup (which is relatively slow).

``````"Dear "+ assign(
lookup( "CustomerFile","CustomerNumber",custID,"Name","",0),"tempCustomerName")+
","+cr()+
tempCustomerName+", you are invited to particpate blah blah blah. "+
tempCustomerName", you won't want to miss out on this blah blah blah"
``````

Note: Panorama now includes a cache( function that is similar to assign, but automatically creates a temporary variable for the duration of the formula itself. In the example above you could use cache( instead of assign(, eliminating the need to create the tempCustomerName variable in advance with a global or fileglobal statement. Any variables created with the cache( function are automatically disposed of when the formula evaluation is complete.

If you use the ?( function in combination with the assign( function be careful because the assign( function will always be evaluated. It doesn’t matter whether the assign( function is in the true or false part of the ?( function.

When the assign( function is used with a field, the field display will not be updated automatically. You’ll need to do that separately with showfields, showcolumns, etc. (depending on what operation you have done).

Assigning a value to a field in a formulafill (or select) in a multi-user shared database doesn’t work. There’s no warning.

• assignglobal( -- assigns a value to a global variable (creating the variable if necessary).
• cache( -- stores a value in a temporary variable.
• callerslocalvariablevalue( -- allows a subroutine to access a local variable in the procedure that called it.
• cardvalidate -- verifies that a number is a valid credit card number.
• convertvariablestoconstants -- converts all of the variables in a formula into constant values.
• datatype( -- determines what kind of data is in a field or variable: text, number, etc.
• datavalue( -- returns the value of a field or variable: text, number, etc.
• fieldstotextvariables -- copies database fields into variables.
• fileglobal -- creates one or more fileglobal variables.
• fileglobalvalue( -- accesses a fileglobal or permanent variable from other databases.
• global -- creates one or more global variables.
• globalvalue( -- returns the value of a global variable.
• ignore( -- ignores all but the first parameter, which is passed through.
• increment -- increments a field or variable.
• info("callerslocalvariables") -- returns a list of local variables defined in the procedure that called the current procedure.
• info("filevariables") -- builds a carriage return separated text array containing a list of the currently allocated fileglobal variables in the current database.
• info("globalvariables") -- builds a carriage return separated text array containing a list of the currently allocated global variables.
• info("localvariables") -- builds a carriage return separated text array containing a list of the currently allocated local variables.
• labelize( -- returns the value of a field or variable along with a label. This saves typing when you need to display fields or variables when logging and debugging.
• labelizeformula( -- returns the value of a formula along with the formula itself as a label.
• labelizeinfo( -- returns the value of an info( function, along with the function itself as a label.
• local -- creates one or more local variables.
• localparameters -- creates one or more local variables and assigns parameter values to them.
• localvalue( -- returns the value of a local variable.
• makefileglobals -- creates one or more fileglobal variables, and assigns a value to each new variable.
• makeglobals -- creates one or more global variables, and assigns a value to each new variable.
• makelocals -- creates one or more local variables, and assigns a value to each new variable.
• permanent -- creates one or more permanent variables.
• savelocalvariables -- saves local variables as a procedure.
• scopes( -- returns the current scope of a variable, as well as any hidden scopes.
• scopevalue( -- returns the value of a variable in the specified scope.
• setcallerslocal -- allows a subroutine to modify a local variable in the procedure that called it.
• setfileglobal -- sets the value of a fileglobal variable (optionally in another database).
• setfilevariable -- sets the value of a fileglobal variable in another database.
• setpermanentvariable -- sets the value of a permanent variable in another database. The database must be open. An empty value will choose the currently active database.
• setwindowglobal -- sets the value of a windowglobal variable (optionally in another window).
• showvariables -- forces Panorama to update the display of one or more variables on every form in the active database.
• showwindowvariables -- forces Panorama to update the display of one or more variables in the currently active form.
• tokenname( -- returns the name of a field or variable (instead of the value contained in the field or variables).
• undefine -- destroys one or more variables.
• undefinefileglobal -- destroys one or more fileglobal variables.
• undefineglobal -- destroys one or more global variables.
• undefinewindowglobal -- destroys one or more windowglobal variables.
• unpermanent -- converts one or more permanent variables into regular fileglobal variables. The variables will no longer be saved as part of the database.
• windowglobal -- creates one or more windowglobal variables.
• windowglobalvalue( -- accesses a windowglobal variable from other windows.

History

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