12.10.5    Perform arithmetic on Tags and Variables

Addition

SETVAL tag2=[expr [GETVAL tag1]+[GETVAL tag2] ]
set sum [expr $x + $x1 +$X2]

Multiplication

SETVAL anatag1=[expr [GETVAL anatag2] * 10]
set GroupEnd [expr $GroupStart * 3]

Trigonometric Functions

set x [expr [GETVAL slope]/100]

set y [expr atan($x)]
 

SETVAL radians=$y

SETVAL degrees=[expr $y*180/3.14159265]

 

The expr command is required to do math.

SETVAL anatag1=[expr [GETVAL anatag2] * 10]

SETVAL anatag1=[expr $scriptvariable2 * 10]

set scriptvariable1 [expr [GETVAL anatag2] * 10]

set scriptvariable1 [expr $scriptvariable2 * 10]

1) Math in tcl requires the use of the expr  command enclosed in [ ] or " ".

2) GETVAL is required by the tcl 'keywords' (i.e. built-in tcl commands like expr) to get the value of a WebAccess TAG.

The @ does not work with tcl 'keywords' (i.e. built-in tcl commands like expr).The @ is a shortcut for ACTION commands.  If the command is in CAPITALS then @ will work.  If the command is lower-case, you must use [GETVAL ].

3) $ is required by the tcl 'keywords' to return the value of a local script variable (e.g. a variable created with the "set" command).

4) Tcl uses a syntax that interprets spaces as end of a command unless a delimiter is used.  A delimiter can be curly brackets { }, square brackets [ ] or quotes " ".  The delimiters are evaluated differently.

Square brackets [ ] are usually used with the expr command.

Curly Brackets { } are evaluated as literal command with no substitution.  

12.3 Command syntax

12.3.1 Brackets [ ]  

12.3.2 Quotes " "

12.3.3 Curly braces { }

12.3.3.1 Braces or Quotes or Brackets

5) Trigonometric functions (sin, cos, tan, etc.) use RADIANS as there output or expected input (not degrees). To convert radians to degrees, multiply by 57.2957795 (which is 360 divided by 2 pi).