0
Script Example - Summing Values In a Grid (version 22)
Knowledge Base / Version 22 / Client Tools / Axiom / Applications
The following code snippet demonstrates how to add 3 values together and display the sum in a 4th value box. The controls do not necessarily need to be values boxes, but could include donut gauges, linear gauges, and circular gauges. For this example, the controls MUST all reside in the same row of a grid as the grid row is a "parent" container of the value boxes.
// NOTE: control is expected to have a GridRow parent (for use in Grid only)
// IMPORTANT: for use with OnEndValueChange of each control used in the equation
public void ValueBox1_OnEndValueChange(object sender, TagSubscriptionArgs subscription, TVQ tvq)
{
IControlParent parent = (sender as ControlBase).Parent;
// get values of first 3 controls in grid row
TVQ tvq1 = ControlBase.GetProperty<TVQ>(parent.Children[0], "Value");
TVQ tvq2 = ControlBase.GetProperty<TVQ>(parent.Children[1], "Value");
TVQ tvq3 = ControlBase.GetProperty<TVQ>(parent.Children[2], "Value");
// calculate sum of values
double sumValue =
(tvq1?.ValueToDouble() ?? 0) +
(tvq2?.ValueToDouble() ?? 0) +
(tvq3?.ValueToDouble() ?? 0);
TVQ sumTVQ = new TVQ(DateTime.Now, sumValue, 192);
// update 4th control in grid row with result
ControlBase.SetProperty(parent.Children[3], "Value", sumTVQ);
}
To edit the script...
- Select the first ValueBox then select the script icon within the 'OnEndValueChange' property. (Note: You must have admin permissions in order to edit the script of an Axiom application.)
- Copy/Paste the code snippet into the script then click 'APPLY & CLOSE'.
- Select the 2nd and 3rd ValueBox and link them to this same function by selecting the 'ValueBox1_OnEndValueChange' from the drop-down list.
This script will run anytime any one of the 3 ValueBoxes receives a new value and updates the 4th ValueBox.