Defining Variables
  • 30 Jan 2024
  • PDF

Defining Variables

  • PDF

Article summary

Dim

Variable names that are used in calculations must be defined.  For normal calculations, the variables are defined as:

                Dim NewValue as Single

The variable name is “NewValue”.   Example code is:

Dim NewValue as single

‘Sum Input tags 3, 5 and 9 and place in Output tag 4

 NewValue =  GD(3) + GD(4) + GD(9)

Tag(4, NewValue)

Static

Variable names that are used for doing calculations must be defined.  Normally they are defined with the Dim statement.  Each time the routine is executed, the number is zeroed.  To keep the value between iterations, define the variable using Static as follows:

                Static OldValue as Single

The variable name is “OldValue”.   Example code is:

 Dim NewValue as single

Static OldValue as single

‘Sum Input tags 3, 5 and 9 and place in Output tag 4

NewValue =  GD(3) + GD(4) + GD(9)

If OldValue <> NewValue then

Tag(4, NewValue)

End If

OldValue = NewValue


Was this article helpful?

What's Next