Array - Create

Declaration

<AMARRAY NAME="text" ROWS="number" COLUMNS="number" DEPTH="number" DESCRIPTION="text" TYPE="text (options)" PRIVATE="YES/NO" ISPARAMETER="YES/NO" />

Related Topics    

Description

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 could be useful to create an array to store data read from a text file or other system containing customer data. If there were 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 dimensioned array. An array can also be a simple list of text values which would 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, etc).
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
  • TYPE="text"
  • TYPE="number"
Causes the variable to assume a specific type. The available options are:
  • Auto (default) - The variable auto-detects whether it contains a number or text adapts to the proper type when possible, depending on the operation being performed.
  • Text - The variable is always treated as text, regardless of its contents. If an operation is attempted that is only valid for numbers, an error will be thrown.
  • Number - The variable is always treated as a number, regardless of its contents. If an operation is attempted that is only valid for numbers, an error will be thrown.
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) that were 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 may have 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.

Description

Error Causes

On Error

Examples

NOTE:
  • 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

This sample task creates a simple array.

Copy
<AMARRAY NAME="MyArray" TYPE="TEXT" ROWS="3" />
<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

This sample task creates an array with the Loop - Files activity (requires a folder called c:\test\ with a few files in it).

Copy
<AMVARIABLE NAME="thefilename" />
<AMVARIABLE NAME="counter" />
<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

This sample task creates a two-dimensional array with the Loop - Files activity (requires a folder called c:\test\ with a few files in it).

Copy
<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" />