Arrays

Arrays are used to represent data in a task that may be different each time a task runs. But unlike standard variables, arrays can contain multiple rows and optionally multiple columns. Unlike Datasets, Arrays are accessed by number. For example, to retrieve the element in Row 2, Column 10 use the expression %arrayname(2,10)%

An array can be used to store data read from a text file or other system containing customer data. For instance, if there are 10 customers, the array would need to have 10 rows, and if the data consisted of firstname, lastname, and company name, it would need 3 columns and would need to be a two dimensional array. An array can also be a simple list of text or numeric values (multiple rows only, one column). This is called a one dimensional array.

What is the difference between a one and two dimensional array?

An array with only one dimension is linear; it contains a list of data that can be referenced by a number. For example if my one dimensional array named myArray had 3 values, then:

myArray(1) = value1

myArray(2) = value2

myArray(3) = value3

In a two dimensional array, you have both rows and columns. It works like a spreadsheet. You reference a cell by row and column, like this:

%Myarray(1,5)%

Creating Arrays

To create an array, use the Create Array action. You give your array a name a set its size. You also choose whether you want your array to be a one dimensional array or two-dimensional array, sometimes called a matrix.

To set a value in an array, use the Set Variable action and for the variable name specify arrayname(row, column [only if two dimensional]).

Examples

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

Example 1 - This is a simple task that associates each array with a color.

<AMARRAY NAME="myarray" TYPE="TEXT" ROWS="3" />

<AMSET VARIABLENAME="myarray(1)">Red</AMSET>

<AMSET VARIABLENAME="myarray(2)">Blue</AMSET>

<AMSET VARIABLENAME="myarray(3)">Green</AMSET>

Example 2 - This task is a more complex task that performs loops (requires a folder called C:\test\ with a few files in it).

<AMVARIABLE NAME="thefilename"></AMVARIABLE>

<AMVARIABLE NAME="counter"></AMVARIABLE>

<AMARRAY NAME="myarray" TYPE="TEXT" ROWS="%FileCount('c:\test\')%" />

<AMLOOP TYPE="FOLDER" FOLDER="c:\test\" RESULTVARIABLE="thefilename">

<AMINCREMENTVARIABLE RESULTVARIABLE="counter" />

<AMSET VARIABLENAME="myarray(%counter%)">%thefilename%</AMSET>

</AMLOOP>

<AMLOOP TOTALLOOPS="%UBound(myarray, 1)%" RESULTVARIABLE="counter">

</AMLOOP>

See Also

Create Array action

About Variables

About Expressions

BASIC Scripts