- 06 Feb 2024
- Print
- PDF
Using Variables and Arguments
- Updated on 06 Feb 2024
- Print
- PDF
Purpose: Learn to create a formula with a variable and multiple arguments.
Task: Build a formula that calculates the cost per ton of a chemical addition to the process.
Sample Formula = Flow of Chemical * Cost of chem / Production rate
Use appropriate tags from your system or sample tags for the chemical flow and production rate.
Steps:
Find tags for the chemical flow and production rate in Tag Browser and drag them onto a Trend. Note the units of each tag, as they are needed to do unit conversion in the calculation.
Right-click the Production Rate tag and choose Script Editor.
In the Script Editor, change the Script Type to Formula.
Name the formula by filling in the Formula: field with the formula name (no spaces or special characters). Change the Data Type to Numeric.
Click on the Arguments tab and create two arguments:
ChemFlowTag Type String
ChemCost Type Double
Build the calculation in the formula area using Argument variables:
Type: “OV = IV(ChemFlowtag) * ChemCost * 60 * 60 / IV”
The logic is:
Chemical in Liters/Second * Cost in $/Liter * 60 Second/Minute * 60 Minutes/ Hour
which is all then divided by the production rate in Mt/Hr to get a final value of $/Mt.
(If the units of the input tags are different from this example, make the necessary adjusments to the calculation logic).
Click the Save Formula button.
Drag the Chemical Flow tag from Tag Browser into the argument grid as the value of ChemFlowTag variable.
Type a number into the argument grid as the value of ChemCost variable. This will be used for calculating test results.
Click the Run button to see example results on the Calc View tab.
Add the calculated tag to the trend. Edit the tag name to manually change the value of the ChemCost variable.