About Arrays

What is an Array?

Like variables, 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)%

How is an array useful?

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, 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 %Myarray(1,5)%.

Creating AutoMate Arrays

To create an array, use the Create Array action. You give your array a name a set it’s 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])


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


Example 1 - Simple Sample

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



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





Example 2 - Sample With Loops (requires a folder called c:\test\ with a few files in it.



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



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


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




Example 3 - Sample with Loops using two dimentioned array (requires a folder called c:\test\ with a few files in it. Array has a row for each file in the folder. 3 column hold filename, size and date)



<AMARRAY NAME="myarray" ROWS="%FileCount('c:\test\')%" COLUMNS="3" DESCRIPTION="array to hold filename size and date" />



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

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

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


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

     <AMMESSAGEBOX>Filename: %myarray(counter, 1)%

File Size: %myarray(counter, 2)%

File Date: %myarray(counter, 3)%</AMMESSAGEBOX>


See Also

Create Array action

About Variables

About Expressions

BASIC Scripts