LIST TO ARRAY
LIST TO ARRAY ( list ; array {; itemRefs} )
Parameter | Type | Description | |
---|---|---|---|
list | Text, Integer | → | Name or Reference of list from which to copy the first level items |
array | Array | ← | Array to which to copy the list items |
itemRefs | Array | ← | List item reference numbers |
This command is not thread-safe, it cannot be used in preemptive code.
Description
The LIST TO ARRAY command creates or overrides the array array with the first level items of the list or choice list designated by list.
In the list parameter, you can pass either the name of a choice list (string), or a reference to a hierarchical list (ListRef).
If you do not set the array as an Alpha or Text type beforehand, LIST TO ARRAY creates a new Text array by default.
Note: In compiled mode, the array must have been defined previously and cannot be retyped.
The optional itemRefs parameter (a numeric array) returns the list item reference numbers.
You can use LIST TO ARRAY to build an array based on the first level items of a list. However, this command does not allow you to work with any of the list's child items. When working with hierarchical lists, we recommend that you use the hierarchical lists commands, in particular Load list.
Example 1
The following example copies the items of a list called Regions into an array called atRegions:
LIST TO ARRAY("Regions";atRegions)
Example 2
Given a hierarchical list created as follows:
myList2:=New list
APPEND TO LIST(myList2;"Scotland";1)
APPEND TO LIST(myList2;"England";2)
APPEND TO LIST(myList2;"Wales";3)
myList1:=New list
APPEND TO LIST(myList1;"France";1)
APPEND TO LIST(myList1;"Germany";2)
APPEND TO LIST(myList1;"Spain";3)
APPEND TO LIST(myList1;"Great Britain";4;myList2;True)
APPEND TO LIST(myList1;"Portugal";5)
APPEND TO LIST(myList1;"Belgium";6)
APPEND TO LIST(myList1;"Italy";7)
APPEND TO LIST(myList1;"Netherlands";8)
APPEND TO LIST(myList1;"Ireland";9)
This list can be represented as:
If you execute the following statement:
LIST TO ARRAY(myList1;$MyArray)
...you get
$MyArray{1}="France"
$MyArray{2}="Germany"
$MyArray{3}="Spain"
$MyArray{4}="Great Britain"
$MyArray{5}="Portugal"
...