12.5.2         array

Description:   Creates and sets the values of one or more elements in an array. Performs other actions on existing arrays

Syntax:         array option arrayName ?arg arg ...?

 

Arguments:    action option, arrayname, arguments

Returns:         Tcl error codes

See Also:       set, SETVAL, @, BINDVAR, GETVAL, $, append, lappend, string

 

Example:     

# Build an array of IO Tag names

array set array1 [list \

1 {48ExServ_Fl_1001} \

2 {48ExServ_Fl_101} \

3 {48ExServ_Fl_1101} \

4 {48ExServ_Fl_1201} \

5 {48ExServ_Fl_1301} \

6 {48ExServ_Fl_1402} \

7 {48ExServ_Fl_1501} \

8 {48ExServ_Fl_1601} \

9 {48ExServ_Fl_1701} \

10 {48ExServ_Fl_1801} \

11 {48ExServ_Fl_1901} \

12 {48ExServ_Fl_2001} \

13 {48ExServ_Fl_201} \

14 {48ExServ_Fl_22} ]

 

# Get value of each tag and sum together

catch {

 for {set i 1; set sum1 0} {$i <= 14} {incr i} {

  set x [GETVAL $array1($i)]

  set sum1 [expr "$sum1 + $x"]

      }

}

 

# Pass value  of sum to Constant Tag

SETVAL %DALOGSTATUS=0

SETVAL CALC49=$sum1

SETVAL %DALOGSTATUS=1

array set arrayName list

Creates an array and sets the values of elements. The list command must consist of an even number of element pairs. Each pair consists of the index (the position number) in the array and the value for that element. The Odd-numbered element in the list is the index within array. The following even element in list is used as the value.  In the example above, then numbers 1, 2, 3, etc are the index and 4SEXServ_FL_1001 are the values at each position in the array.

If the variable arrayName does not already exist and list is empty, arrayName is created with an empty array value.

array size arrayName

Returns a decimal string giving the number of elements in the array. If arrayName isn’t  an array, then 0 is returned.