Array - Create
Declaration
<AMARRAY NAME="text" ROWS="number" COLUMNS="number" DEPTH="number" DESCRIPTION="text" TYPE="text (options)" PRIVATE="YES/NO" ISPARAMETER="YES/NO" />
Overview
Creates a one, two or three dimensional array for storing multiple items in sequential order with the same variable name.
Practical usage
An array is a special type of Automate Desktop variable used to store data with multiple rows and/or columns. It can be useful to create an array to store data read from a text file or other system containing customer data. If there are 10 customers, the array needs to have 10 rows, if the data consisted of first name, last name, and company name it needs 3 columns and needs to be a two dimensioned array. An array can also be a list of text values that take up multiple rows but only a single column, also known as a single dimensioned array.
Parameters
General
| Property | Type | Required | Default | Markup | Description |
|---|---|---|---|---|---|
| Array name | Text | Yes | (Empty) | NAME="myarray" | The name of the array to create. It is important that this value is unique, descriptive and does not conflict with any BASIC scripting keywords (examples of common conflicts include: date, day, week, and so on). |
| One dimension | Number | No | (Empty) | ROWS="value" | If enabled (default), specifies creation of a one-dimensional array (or single dimension array). Accessing its elements involves a single subscript which represent a row index. If this parameter is enabled, the Two dimension and Three dimension parameters are disabled. |
| Two dimension | Number | No | Disabled | ROWS="value1 COLUMNS="value2" |
If enabled, specifies creation of a two-dimensional array (or double-dimension array). Its elements represent a row and column index. If this parameter is enabled, the One dimension and Three dimension parameters are disabled. This parameter is disabled by default. |
| Three dimension | Number | No | Disabled | ROWS="value1" COLUMNS="value2" DEPTH="value3" | If enabled, specifies creation of a three-dimensional array (or triple-dimension array). Its elements represent a row, column and depth index. If this parameter is enabled, the One dimension and Two dimension parameters are disabled. This parameter is disabled by default. |
Advanced
| Property | Type | Required | Default | Markup | Description |
|---|---|---|---|---|---|
| Variable type | Text (options) | No | Auto |
|
Causes
the variable to assume a specific type. The available options
are:
|
| Variable is private | Yes/No | No | No | PRIVATE="YES" | If selected, this parameter specifies the variable is only available to the current (or parent) task and not to any sub-tasks (or child tasks) started with the Task - Start sub-task activity. If disabled, the variable is available to sub-tasks. This parameter is disabled by default. |
| Treat as parameter | Yes/No | No | No | ISPARAMETER="YES" | If selected, this parameter specifies the variable is only created if it does not already exist. This is particularly useful when a task has parameters passed to it at runtime (that is, variables of the same name are created automatically), but a default value should be assumed when debugging and parameters are not present. |
| Description (optional) | Text | No | (Empty) | DESCRIPTION="Date variable" | An optional text description to describe the purpose of the variable. T this information is displayed at design time in the Variables debug panel. |
Examples
- Copy and paste the sample AML code below directly into the Task Builder Steps Panel.
- To successfully run the sample code, update parameters containing user credentials, files, file paths, or other information specific to the task to match your environment.
Example 1
The following sample task creates a simple array:
<AMARRAY NAME="MyArray" ROWS="3" TYPE="text" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="MyArray(1)" VALUE="Red" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="MyArray(2)" VALUE="Blue" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="MyArray(3)" VALUE="Green" />
<AMSHOWDIALOG>%MyArray(1)%; %MyArray(2)%; %MyArray(3)%</AMSHOWDIALOG>
Example 2
The following sample task creates an array with the Loop - Files activity (requires a folder called c:\test\ with a few files in it):
<AMVARIABLE NAME="thefilename" VALUE="" />
<AMVARIABLE NAME="counter" VALUE="" />
<AMARRAY NAME="MyArray" ROWS="%FileCount('c:\test\')%" TYPE="text" />
<AMLOOP ACTIVITY="folder" FOLDER="c:\test\" RESULTVARIABLE="thefilename" />
<AMLOOP FROM="1" TO="%UBound(myarray, 1)%" RESULTVARIABLE="counter" />
Example 3
The following sample task creates a two-dimensional array with the Loop - Files activity (requires a folder called c:\test\ with a few files in it):
<AMVARIABLE NAME="thefilename" VALUE="" />
<AMVARIABLE NAME="counter" VALUE="" />
<AMARRAY NAME="myarray" ROWS="%FileCount('c:\test\')%" COLUMNS="3" DESCRIPTION="array to hold filename size and date" />
<AMLOOP ACTIVITY="folder" FOLDER="c:\test\" RESULTVARIABLE="thefilename" />
<AMVARIABLE ACTIVITY="set" VARIABLENAME="myarray(%counter%, 1)">%thefilename%</AMVARIABLE>
<AMVARIABLE ACTIVITY="set" VARIABLENAME="myarray(%counter%, 2)">%FileLen(thefilename)%</AMVARIABLE>
<AMVARIABLE ACTIVITY="set" VARIABLENAME="myarray(%counter%, 3)">%FileDateTime(thefilename)%</AMVARIABLE>
<AMLOOP ACTIVITY="end" />
<AMLOOP TOTALLOOPS="%UBound(myarray, 1)%" RESULTVARIABLE="counter"><AMSHOWDIALOG>Filename: %myarray(counter, 1)%File Size: %myarray(counter, 2)%File Date: %myarray(counter, 3)%</AMSHOWDIALOG></AMLOOP>
<AMSHOWDIALOG>Filename: %myarray(counter, 1)%File Size: %myarray(counter, 2)%File Date: %myarray(counter, 3)%</AMSHOWDIALOG>
<AMLOOP ACTIVITY="end" />