Use Tag Values in Expressions

This information applies to expressions created within the Expression Editor.
It does not apply to VTScada script code created in modules such as custom-coded reports.

In expressions, tag names are enclosed in square brackets: [Level] or [<Station 1\PLC1\Level>]. The first example is an open relative reference to the name and the second is an absolute reference that displays the name but actually uses the tag's unique ID. The tag selector that is built into the expression editor will always return an absolute reference; you may need to shorten that if you need an open relative reference instead.

If you want to see the value of some property of the tag, you must say which property. For example, [Level]\Value, [Level]\ShortName, [Level]\Area. Note the location of the backslash relative to the brackets. Switching the order is a common mistake.

VTScada offers a shortcut for \Value because this is what you will want in most cases: If no property is specified, VTScada assumes that you want the tag's current value. Therefore, [Level] is always taken as [Level]\Value. It will never return a reference to the tag object itself.

Advanced expression writers take note: If you are attempting an expression that builds a tag reference on the fly, [Level] will always be returned as [Level]\Value. To obtain a reference to the tag object itself, your expression must build that as [Level]\Root or Scope(Self, "Level")\Root).
For all readers: the \Root suffix is not needed or used in 99.999% of expressions!

If the tag is not nearby in the hierarchy, you will need to tell VTScada where to find it. For example, given the following tag structure:

Expression to be created in \Station 1\PLC1 using Level

If you are creating an expression in a tag that is a child of PLC1 and that uses the value of Level, you would write it as [Level], as shown:

[Level] * 2 / 3 ; two thirds of the  value

If you want to refer to a tag that is not an immediate sibling in the tag hierarchy, you will need to provide the address for where to find it.

Let's say that there is also a Station 2 with a level, and you want a calculation to show the average of the two:

([Level] + [Station 2\PLC1\Level]) / 2 ; the average of two tank values.

Level within Station 1 can be found just by its name, but you must provide a path to the tag named Level in Station 2.

The following tools are available to help you specify tags in the hierarchy. All of these are used inside the square brackets that denote a tag name.

\ Divider between parent and child tag names.
..\ Forces VTScada to start searching one level up the hierarchy tree. Always use this when the property you want to refer to in a parent might also exist in the current tag.
Child\GrandChild To reference a value (or other property) from a child of the current tag, start with the name of the child tag, then a backslash between each subsequent child name.
*TagType
..\*TagType
Ancestor Relative Path, used when selecting a parent tag of a given type.
For example, if you want a calculation tag to refer to the first parent that is a driver, use [*Driver]. (*)
If you want it to refer to the first parent that has a numeric value, you can use [..\*Numeric]. The ..\ portion is necessary to prevent the calculation tag from finding itself.
<> Absolute path. The tag name must start immediately below the root level of the tag hierarchy.

(*) Types you are likely to use most often include: *Port, *Driver, and *Numeric.

There are advantages and disadvantages to each method. For each situation, VTScada defaults to what is most likely to be useful in that situation. "Likely" doesn't mean "always".

The Scope Function and Tags

VTScada handles tag addresses differently in different situations. In a tag's configuration, other tags are usually identified using relative addresses, [Tag Name]. In the Idea Studio, widgets link to tags using absolute addresses [<Full Tag Name>].

If you are writing a VTScada script code module, you can't use the square bracket shortcut. Instead, you must use the scope function:

Scope(Self, "Full Tag Name or GUID", TRUE)\Attribute

If providing a full tag name, do not include the brackets. Providing the tag's GUID is equivalent to the short form, [< >]. "Attribute" is not a keyword here; use \Value or \Description, etc. If you don't provide an attribute, then the Scope function returns a link to the tag object itself, not the value.

If adding expressions to tags in an exported Excel file, you cannot use relative references such as [TagName]. All existing expressions are exported using the full syntax and with certain characters doubled: "Scope(Self, "TagName")\\Value". You must do the same.