Use a Tag’s Value in an Expression

You can obtain and use the value of any tag in your application using the following syntax:

Variable(“TagName”)\Value

The TagName referred to can be any tag in your application.

For example, if you want to find the total value of three analog inputs that are monitoring tank volumes, you might write the following expression:

Variable("TankVolume_1")\value +

Variable("TankVolume _2")\value +

Variable("TankVolume _3")\value

 

Caution:   Tag values may be “Invalid”, especially at system startup.  The result of any calculation on an Invalid is always Invalid.  (For example,  1 + 0 is 1, but 1 + Invalid is Invalid.)

 

To avoid errors and the possible repercussions of returning an unwanted Invalid value, you can use the PickValid function to supply a default value.

 

The PickValid function examines a list of values that you provide as parameters.  The first value that is not Invalid will be the one returned.

PickValid( Variable(“TankVolume_1”)\value,  0)  

-     Returns the value of TankVolume_1 when that tag’s value is Valid

-     Returns 0 when the tag’s value is Invalid.

 

The expression shown earlier that calculates the sum of three tank volumes can be written as follows:

PickValid(Variable("TankVolume_1")\value, 0) +

PickValid(Variable("TankVolume _2")\value, 0) +

PickValid(Variable("TankVolume _3")\value, 0)

Should any tag’s value go to Invalid for any reason, this expression will substitute 0 for its value. 

Note that the PickValid function should be used with care:  There may be instances where it would be better to return an invalid rather than an incorrect value.