Array Commands (V26/V27)
V26 introduced array operations for one-dimensional dynamic numeric arrays. V27 extended with DELETE and INSERT.
ARRAY ASSIGN
Syntax:
ARRAY ASSIGN a(), valueFills all elements of a dynamic array with a single value.
REDIM nums(1 TO 5) AS LONG ARRAY ASSIGN nums(), 7 ' All elements = 7
ARRAY REVERSE
Syntax:
ARRAY REVERSE a()Reverses the order of elements in a dynamic array.
nums(1)=1: nums(2)=2: nums(3)=3 ARRAY REVERSE nums() ' Now: 3,2,1
ARRAY SORT
Syntax:
ARRAY SORT a()Sorts a dynamic numeric array in ascending order.
nums(1)=7: nums(2)=3: nums(3)=5 ARRAY SORT nums() ' Now: 3,5,7
ARRAY COPY
Syntax:
ARRAY COPY src() TO dst()Copies all elements from source array to destination array. Destination is automatically REDIM'd.
REDIM src(1 TO 3) AS LONG REDIM dst(1 TO 1) AS LONG ARRAY ASSIGN src(), 42 ARRAY COPY src() TO dst()
ARRAY SCAN
Syntax:
ARRAY SCAN a(), = value TO resultSearches for an element matching a value. Result receives the 1-based index, or 0 if not found.
ARRAY SCAN nums(), = 7 TO found IF found > 0 THEN PRINT "at index "; found
ARRAY DELETE (V27)
Syntax:
ARRAY DELETE a(index)Removes an element from a dynamic array. Following elements shift down.
ARRAY INSERT (V27)
Syntax:
ARRAY INSERT a(index), valueInserts a value at the given position. Following elements shift up.
Current limit: These commands target one-dimensional dynamic numeric arrays. Multi-dimensional and STRING array support is future work.