convertvariablestoconstants

convertvariablestoconstants

ORIGINALFORMULA

, NEWFORMULA

The** convertvariablestoconstants **statement converts all of the variables in a formula into constant values.

**Parameters**

This statement has two parameters:

** originalformula** – source text of formula.

** newformula** – field or variable to receive the modified formula. If this parameter is missing, the first parameter must be a field or variable containing the formula, and the modified formula will be placed back into that field or variable.

**Description**

This statement converts all of the variables in a formula into constant values. This essentially “freezes” the formula, allowing it to be used later in a different context where the original variables may no longer be available. For example, you could transfer the formula from one computer to another (perhaps client to server), or store the formula and use it again at a later time.

For example, consider this program that prompts for a zip code and distance, and then saves a formula in a permanent variable named *searchFormula*.

```
let searchZip = ""
gettext "Zip Code",searchZip
let searchDistance = "10"
gettext "Search Distance (miles)",searchDistance
searchDistance = val(searchDistance)
letpermanent searchFormula = {zipdistance(searchZip,ZipCode)<searchDistance}
convertvariablestoconstants searchFormula
```

Suppose you run this formula, and enter *91306* as the zip code and *15* as the distance. The formula stored in the permanent variable has been converted from:

```
zipdistance(searchZip,ZipCode)<searchDistance
```

into:

```
zipdistance("91306",ZipCode),15
```

As you can see, the two variables in this formula have been replaced with their actual values. (The *ZipCode* field in the formula has not been touched.)

Later you can run another program that uses this formula to run a selection:

```
execute "select "+searchFormula
```

This selection will work fine even though the *searchZip* and *searchDistance* variables don’t exist any more. Even though the variables are gone, their values have been hard coded into the saved formula.

Here’s a slightly different version of the original program. In this case, the original formula has been embedded into the *convertvariablestoconstants* statement directly, with the result coming into the second parameter (*searchFormula*). When using two parameters like this, the formula should not be quoted as it was in the first example).

```
let searchZip = ""
gettext "Zip Code",searchZip
let searchDistance = "10"
gettext "Search Distance (miles)",searchDistance
searchDistance = val(searchDistance)
permanent searchFormula
convertvariablestoconstants zipdistance(searchZip,ZipCode)<searchDistance,searchFormula
```

These examples may seem a bit contrived, obviously you could arrange to store the searchZip and searchDistance values separately in permanent variables. The advantage of the *convertvariablestoconstants* statement is that it allows you to construct and save an arbitrarily complex formula as a single entity, with no special arrangements for saving whatever variables are included. This statement is used this way internally by ProVUE for several features in Panorama Server, especially for passing formulas between computers.

**See Also**

- Arithmetic Formulas -- mathematical operators and functions.
- assign( -- assigns a value to a field or variable, also returning the value.
- 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.
- Characters and Unicode Values -- working with individual characters of text.
- Constants -- values embedded into a formula.
- 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.
- Date Arithmetic Formulas -- performing calculations on dates, and converting between dates and text.
- fieldstotextvariables -- copies database fields into variables.
- fileglobal -- creates one or more fileglobal variables.
- fileglobalvalue( -- accesses a fileglobal or permanent variable from other databases.
- Formula Workshop -- formula workshop wizard for testing and experimenting with formulas.
- formulacalc -- allows you to evaluate a formula that you were not able to code into the procedure when it was being written.
- formulafields( -- returns a list of fields used in a formula.
- formulaidentfiers( -- returns a list of identifiers (fields and variables) used in a formula.
- Formulas -- basics of formulas: components and grammar.
- formulavalue -- calculates the result of a formula. Usually this is done with an assignment statement (for example `x=2 * y` ), but the *formulavalue* statement gives you more flexibility. You can specify what database is to be used for the calculation (an assignment statement always uses the current database) and you can specify the formula using a variable, making it easy to change on the fly. This statement also gives you more control over how errors are handled.
- formulavariables( -- returns a list of variables used in a formula.
- Functions -- index of all functions available for use in Panorama formulas.
- global -- creates one or more global variables.
- globalvalue( -- returns the value of a global variable.
- 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.
- Linking with Another Database -- multiple database files working together.
- 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.
- makemergeformula( -- builds a formula from an “auto-wrap" style merge template.
- Non Decimal Numbers -- working with numbers in alternate (non-decimal) bases, including binary, octal and hexadecimal.
- Numbers -- Working with numeric values in a formula, and converting between numbers and text.
- Operators -- index of all operators available for use in Panorama formulas.
- permanent -- creates one or more permanent variables.
- Quotes -- text constants embedded into a formula
- 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.
- Statements -- index of all statements available for use in Panorama procedures.
- SuperDates -- date and time combined into a single value.
- Tag Parsing --
- Text Formulas -- manipulating text with a formula (concatenation, extraction, rearranging, etc.)
- Time Arithmetic Formulas -- performing calculations on times, and converting between times and text.
- tokenname( -- returns the name of a field or variable (instead of the value contained in the field or variables).
- True/False Formulas -- logical boolean calculations.
- undefine -- destroys one or more variables.
- unpermanent -- converts one or more permanent variables into regular fileglobal variables. The variables will no longer be saved as part of the database.
- Using Fields in a Formula -- accessing database fields within a formula.
- Values -- the raw material that formulas work with -- numbers and text.
- Variables -- storing and retrieving individual items of data, not part of a database.
- windowglobal -- creates one or more windowglobal variables.
- windowglobalvalue( -- accesses a windowglobal variable from other windows.

**History**

Version | Status | Notes |

10.2 | New | New in this version. |