4. Working with Classes : External Classes : How You Can Use Collections with External Classes
 
Share this page                  
How You Can Use Collections with External Classes
ActiveX objects can be collections, which are like sets, and can be used as arrays if they have been declared as an OpenROAD collection. If you want to index into a collection using the array syntax, you first must declare it as an OpenROAD collection.
The following code is an OpenROAD collection example, which is discussed in the paragraphs that follow:
x = sheets;
x1 = sheets a collection of cells;
y = cell;
x.item(1)= y;
x1[1] = y;
In the preceding example, x and x1 are declared as reference variables of the sheets class type. Sheets is an external class that is actually an ActiveX collection. This collection contains objects of the cells class type. The x1 variable is also qualified as an OpenROAD collection. The y variable is declared as a reference variable of the cell class type. The syntax for indexing into the ActiveX collection depends on how the variables are declared. OpenROAD array syntax can be used if the variable is qualified as an OpenROAD collection. Otherwise, the collection is indexed using the standard item method.
The following code shows the indexing of a collection using array syntax:
y = cell;
x = sheets a collection of cells;
x[1]=y;
If the reference variables are declared as follows:
y = cell;
x = sheets
x1 = sheets a collection of cells;
Then the following statements are wrong and will fail:
x[1] = cells;
x1.item(1) = cells;
However, the following statements are correct:
x.item(1) = cell;
x1[1] = cell;
For more information about collections, see Collections (see Collections).