Calculate

Command groupFlag affectedReversibleExecute on clientPlatform(s)
CalculationsNOYESYESAll

Syntax

Calculate
 
field-name
 as 
calculation

Description

This command assigns a new value to a data field or variable. The form of the command is "Calculate X as Y", where X is a valid data field or variable name and Y is either a valid data field or variable name, value, calculation, or notation. When Calculate is executed the state of the flag is unchanged, unless #F is recalculated by this command.

You can use Calculate in a reversible block. The data field returns to its initial value when the method containing the block of reversible commands finishes.

Warning: The Calculate command does not redraw a calculated field so if your field is on a window you must use the Redraw command or the $redraw() method after the Calculate command to reflect the change.

Operator Precedence

Mathematical expressions are evaluated using the operator precedence so that in the absence of brackets, * and / operations are evaluated before + and -. The full ordering from highest to lowest precedence is:

unary minus

* and /

+ and -

>, <, >=, <=, <>, =

& and |

For example, if you execute the command "Calculate lVar1 as 10-2*3" the calculation part is evaluated as 10-(2*3)

Example

# set the local variable lVar1 equal to the contents of lVar2

Calculate
 
lVar1
 as 
lVar2

 
# set the local variable lPrice to 10.99 and lQty to 2

Calculate
 
lPrice
 as 
10.99

Calculate
 
lQty
 as 
2

 
# calculate the local variable lTotal as lPrice multiplied by lQty

Calculate
 
lTotal
 as 
lPrice
*
lQty

 
# you can also operate on variables using notation, for example

# calculate the local list variable lClassList as a list of all classes in the current library

Calculate
 
lClassList
 as 
$clib.$classes.$makelist
(
$ref.$name
)

# however some operations are better performed using the Do command, for example

# bring the window instance wMywindow to the front

Do
 
$iwindows
.
wMywindow
.
$bringtofront
()