User-Defined Functions

In addition to the many functions included with the calculation collector, Historian provides the ability to create custom calculation functions. After a custom calculation function has been created, it is available for use with other calculations.

Functions are useful as shortcuts for large blocks of source code. By creating a function out of commonly used calculation formulas, you can save time and effort instead of typing a few lines of calculation formula every time you want to perform the same operation, it is compressed to a single line.

The syntax of a function is simple:
Function functionname (variable list) 
   [calculation formulas]
End Function

The operations the function performs are contained within the Function / End Function statements. If you need to send data to the function a tagname, for example you simply create a variable in the function's parameters to receive the data. Multiple variables must be separated by commas. These variables exist only within the function.

The following is an example of a function. This function, named checkValue(), looks at a tag and assigns it an alarm if it is over a specified value.

Function checkValue (tagname,sourcename,value) 
  If CurrentValue(tagname) > value Then
  Set AlarmObj = new Alarm 
  AlarmObj.SubConditionName = "HI" 
  AlarmObj.Severity = 750
  AlarmObj.NewAlarm
  "alarmname", "Simulated", "tagname", "Now" 
  checkValue = true
Else 
  checkValue = false
  End If
End Function

To call the function once it has been created, use the following syntax in your calculation formula:

alm_set = checkValue("DD098.FluidBalance","FluidBalance_ALM",5000)

If the function returns a true value (the alarm was set), the alm_set variable will be set to true. If it did not set the alarm, the alm_set variable will be set to false.