Result of Formulas
When a formula is processed, the result of the last statement is saved as the result of the formula and returned to the caller.
The following example generates a signal with a sine wave in several steps:
Dim x, y
// Create data series with 100 increasing time values
x = (100, 0 s, 0.1 s)
// Sine with frequency of 3.5 Hz and amplitude of 5 V
y = 5 V * Sin(2 Pi * 3.5 Hz * x)
// Combine X and Y to form signal
Signal(y, x)
The formula result is the value that is returned by the Signal function.
If you do not want to pass on the result of the last statement, you must use the Return Statement:
If NumberOfRows(Signal) < 2n Then
// If Signal has less than 2 values, then
// pass void floating point value
return ?
End
// Otherwise, calculate sampling rate
1. / (Signal.x[1n] - Signal.x[0n])
FlexPro very rarely re-calculates formulas. It ensures that each formula is only calculated once during an updating process. Formulas with arguments form an exception. These are calculated with each call, even if the same arguments are passed several times.
If there is already a result present from the previous update procedure, FlexPro first checks this to see if it is necessary to do a recalculation. This is the case when the formula is based on data that has changed since the last calculation or the formula uses functions with a result that is deterministic, e.g., the random function. If the existing result is still valid, then it is re-used without a recalculation.