Variables

23.08.2021

In FPScript, you can use variables for interim results. A variable acts as a placeholder where you can store any results of calculations and recall them when necessary. The name of the variable allows access within the formula to the storage location to which it has been assigned.

Before using a variable for the first time, the variable must be declared using the Dim Statement. This creates storage for one or more variables. A variable, which has not yet been assigned a value, is of the Empty data type. You can use an Assignment to assign a value to it. In a variable containing, for instance, a data series, you can specifically overwrite individual values or sections using the Indexed Assignment.

The range of validity for a variable is restricted to the formula in which you use it. Thus, you can use the same variable name in various formulas without risking conflicts.

The local variable SourceData serves a special purpose. For more information on this, read the Lists in Accessing Header Information.

Example

// Declares the two variables i and Series.
Dim i, Series
// Initializes a variable i with the integer scalar value 1.
i = 1n
// Creates a data series with 100 zeros.
Series = 0. # 100n

For complex calculations, it often makes sense to split up the calculation into several statements. In a first statement you could calculate, for instance, a partial expression that you then use in further statements. To do this, it is important to assign the results of the calculations to variables so you can use them later:

// Declare variable
Dim Angle
/ Calculation of angle
Angle = 2 Pi * f * t
// Calculation of an overlapped oscillation
2 * Sin(Angle) + 3 * Cos(Angle)

Here, the calculation of the angle is performed on a separate line.

Share article or send as email:

You might be interested in these articles