# Formulas

N.B. This must be performed on the server.

Fields can have formulas associated with them to allow simple arithmetic functions to be applied before they are displayed or written to.

## 1. Edit the field

See the Adding a Field to a Configuration section for more details. ## 2. Click the ‘Edit’ button next to the ‘Read Formula’ field Formulas have the following syntax:

`value:=expression`

where expression is a mathematical formula, e.g.:

`value:=9*4`

Any field from any of the RTU can be selected and can be included in the calculation, e.g.:

`value:=field("Pressure")`

Multiple fields can also be included in the calculation, e.g.:

`value:=field("Net Flow Rate")-field(Gross Flow Rate")`

Variables can be declared and used as part of the calculation, e.g.:

```var a := 2;
var b := 3;
value := a + b;```

If statements can also be written to display a value based on a Boolean expression being satisfied.The following formula returns how far a value is outside of its two limit fields:

```var temperature := field("Temperature");
var high_temperature := field("Temp Hi-Lim");
if (temperature > high_temperature)
value := temperature - high_temperature;
else
var low_temperature := field("Temp Lo-Lim");
if (temperature < low_temperature)
value := temperature - low_temperature;
else
value := 0;
end if
end if```

The calculation can include any of the following operators. A full list is available in the operator popup menu.

 + Plus - Minus * Multiply / Divide % Mod \ Integer Divide = Equals # Not Equal to < Less Than > Greater Than <= Greater Than or Equal to >= Less Than or Equal to || Logical OR & Logical AND | Bitwise OR && Bitwise AND << Rotate Left >> Rotate Right ! Not ? Bit Test

## 3. Type in the formula:

“value:=value/100″

## 4. Click the ‘Add Field’ button ## 5. Double click on the field to insert it into the formula ## 6. Click the ‘Validate Formula’ button

If the formula is entered correctly a message will be displayed saying “This formula is OK!”. ## 8. Click the ‘OK’ button in the formula window

Note: Write Formulas are exactly the same as read formulas except that the variable used to write the return variable is “writevalue” rather than “value”. The line requires a “;” at the end of the formula. e.g.

`writevalue:=writevalue*100;`