Arrays

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. You may want to think of an array as nothing more than a list, such as a shopping list, to-do list, birthday list, etc. All items in an array, like the items in a list, have a position somewhere between first and last. Items are numbered from lowest to highest in arrays, therefore, they are accessed by number. For example, to retrieve the element in Row 2, Column 10, the following expression would be entered:

 

%arrayName(2,10)%

 

One & Two Dimensional Arrays


An array can be used to store a list of 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 first name, last name, 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 (i.e. multiple rows of data, only one column), this is called a one dimensional array.

An array with only one dimension is linear. In other words, 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 the syntax would be:

 

myArray(1) = value1

myArray(2) = value2

myArray(3) = value3

 

 

In a two dimensional array, you have both rows and columns, such as a  spreadsheet. You would then need to reference a cell by row and column, like the expression below which references row 1, column 5.

 

%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])

Examples

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

 

Sample 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>

<AMSHOWDIALOG>%myarray(1)%

%myarray(2)%

%myarray(3)%</AMSHOWDIALOG>

 

 

 

Sample 2 - This is a more complex task that uses functions and 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">

     <AMSHOWDIALOG>%myarray(counter)%</AMSHOWDIALOG>

</AMLOOP>

 

See Also

Create Array action

About Variables

About Expressions

BASIC Scripts

↑ Top of Page