CreateArrayRept function

Syntax

CreateArrayRept(val, count)

Description

Use the CreateArrayRept function to create an array that contains count copies of val. If val is itself an array, the created array has one higher dimension, and each element (sub-array) is the array reference val.

The type of the first parameter (val) determines the type of array that is built. That is, if the first parameter is of type NUMBER, an array of number is built. If count is zero, CreateArrayRept creates an empty array, using the val parameter for the type.

If you are making an array that is multi-dimensional, val will be the subarray used as the elements.

To make the subarrays distinct, use the Clone method. For example:

&A = CreateArrayRept(&AN, 4).Clone();

Parameters

Parameter Description

val

A value of any type.

count

The number of copies of val contained in the array.

Returns

Returns a reference to the array.

Example

The following code sets &A to a new empty array of string:

&A = CreateArrayRept("", 0);

The following code sets &A to a new array of ten zeroes:

&A = CreateArrayRept(0, 10);

The following code sets &AAS to a new array of array of strings, with two subarrays:

&AAS = CreateArrayRept(CreateArray("one", "two"), 2);

Note that in this case, both elements (rows) of &AAS contain the same subarray, and changing the value of an element in one of them changes it in both of them. To get distinct subarrays, use the Clone method:

&AAS = CreateArrayRept(CreateArray("one", "two"), 2).Clone();

The following example shows how to create a two-dimension array using CreateArrayRept and Push. In addition, it shows how to randomly assigns values to the cells in a two-dimension array.

Local array of array of string &ValueArray; 
&Dim1 = 10; 
&Dim2 = 5; 
&ValueArray = CreateArrayRept(CreateArrayRept("", 0), 0); 
For &I = 1 To &Dim1 
   &ValueArray.Push(CreateArrayRept("", &Dim2)); 
End-For; 
&ValueArray[1][1] = "V11"; 
&ValueArray[2][1] = "V21"; 
WinMessage("&ValueArray[1][1] = " | &ValueArray[1][1] | " " | "&ValueArray[2][1] = " | &ValueArray[2][1], 0);