Using Array Type Variables
- Última atualização2020/05/07
Using Array Type Variables
An array variable is a two-dimensional variable that holds multiple values in a table of rows and columns. Arrays are very powerful for creating staging areas for data that need to be retrieved by your process as it runs.
Common uses of array variables include:
- Extracting data from web pages
- Extracting many rows of data from an Excel spreadsheet or a database
- Read or write data from/to a legacy system, an ERP system, or another application
- Filling out order forms with different fields from Excel to Database
The values can represent either text or numeric data.
After you create the variable, you can use it by inserting the variable in several of the MetaBot commands.
When the value of the variable is modified, this value is reflected in any subsequent commands that are run by the task.
Creating an Array Type Variable
You can create an array type variable in one of two ways:
Direct Assignment
When the values of an array variable need to be defined directly, you can opt to use 'Value' Array type variable. This is termed as 'Direct Assignment'.
To create an array type variable using direct assignment, follow these steps:
-
In the Logic Editor, click the Variable Manager tab on the right side.
- Click on the Add button. The 'Add Variable' window is displayed.
- Select type 'Array'.
- Enter a name for the variable. The name must begin with an alphabet and should not contain spaces.
- Select how you want the array to be created. Default selection is 'Value' which indicates that you will define the values of this variable directly in it. .
-
Specify the number of rows and columns in the field provided. Default values are 1 X 1.
-
Click the Initialize Values button. The Array Value Details window is displayed based on the rows and columns provided in step 6.
-
Enter the values for each cell.
Tip: You can modify the array dimensions using the Add Row, Add Column, Delete Row, and Delete Column buttons. - Click the Save button to save the values.
- Click the Save button in the Add Variable window to save the Array variable.
After the variable is saved, it is displayed in the Local Variables section of the Variable Manager.
If you do not want to specify the value of the variable at the time you create the variable, MetaBot Designer allows you to set the values of variables using a text file. This is described in the next section.
Reading from a Text File
Create an array type variable using text file assignment when you want to read values from a specified text file into the array variable while the task is running. The text file is used to define the array variable.
To create an array type variable using text file assignment, follow these steps:
- Determine the text file that you will use for assigning values.
-
- For Rows enter the data in a new line.
- For Columns use comma separated values.
-
Example: sports_team.txt
- In the Task Editor, click the Variable Manager tab on the right side.
-
Click on the Add button. The 'Add Variable' window is displayed.
- Select type 'Array'.
- Enter a name for the variable. The name must begin with an alphabet character and should not contain spaces.
- Select 'Read from text file' from the list.
- In the Select File field, browse to the file or type the file path for the required text file. Use the Open File button to view the selected text file or to modify it.
- Click Save.
Inserting Array Variables in Screens and DLLs
You can insert Array Variables while creating Logic in the Logic Editor. It can be used to assign values in Screens or Dlls.
-
Adding an Array variable to a Screen - You can add an Array variable in Screens via MetaBot commands; namely Message Box, String Operation, and Variable Operation. You can also assign a variable in the Screen directly in the property window as shown:
-
Adding an Array variable to a Dll - You can insert an Array variable while inputting values by pressing the function key 'F2' as shown: