Examples of Simple Formulas
  • 02 Feb 2024
  • PDF

Examples of Simple Formulas

  • PDF

Article summary

Filter

OV = IV

If IV < MinVal Or IV > MaxVal Then FILTER = True

Average of Tags within a Range     

'This formula averages the value of up to three tags if their values

'have good quality and are between 0 and 10,000

'Shows example of dimensioning variables

Dim iCount As Integer

Dim dSum As Double

Dim PV As PARCValue

iCount = 0

dSum = 0

PV = IV(TAG1)

If PV.Quality <> Opc.Da.Quality.bad Then

        If Convert.ToDouble(PV.Value) > 0.0 And Convert.ToDouble(PV.Value) < 10000.0 Then

                iCount = iCount + 1

                dSum = dSum + Convert.ToDouble(PV.Value)

        End If

End If

PV = IV(TAG2)

If PV.Quality <> Opc.Da.Quality.bad Then

        If Convert.ToDouble(PV.Value) > 0.0 And Convert.ToDouble(PV.Value) < 10000.0 Then

                iCount = iCount + 1

                dSum = dSum + Convert.ToDouble(PV.Value)

        End If

End If

PV = IV(TAG3)

If PV.Quality <> Opc.Da.Quality.bad Then

        If Convert.ToDouble(PV.Value) > 0.0 And Convert.ToDouble(PV.Value) < 10000.0 Then

                iCount = iCount + 1

                dSum = dSum + Convert.ToDouble(PV.Value)

        End If

End If

If iCount > 0 Then

        OV = dSum/iCount

Else

        OV = 0

End If 

Tag Comparison

'Sample Formula to compare two tags value and return a 3rd or 4th tag's value if one has a value greater than the other.

If IV(TAG1) > IV(TAG2) Then

      OV = IV(TAG3)

Else

      OV = IV(TAG4)

End If

Show Text as Output

'An example formula showing how to output text in a calc formula.

'In this formula, if the value is less than 3 it will say "Low" as the tag's value and if greater than 3 then it will show "High" as the value

If IV < 3 Then

  OV = New PARCValue("Low", Opc.Da.Quality.good)

Else

  OV = New PARCValue("High", Opc.Da.Quality.good)

End If


Was this article helpful?