Arrays.ResizeTo

From Xojo Documentation

Method

Arrays.ResizeTo(ParamArray index As Integer)

New in 2019r2

Supported for all project types and targets.

Resizes the array to the specified index.

Usage

arrayName.ResizeTo(ParamArray index As Integer)

Part Type Description
arrayName n/a The name of any previously declared array.
index Integer The new upper bound for the array. Use -1 remove all the array elements. Resizing the array to less than -1 causes an OutofBounds exception.

In the case of multi-dimensional arrays, pass as many index parameters as there are dimensions in the array.

Notes

The ResizeTo method is used to increase or reduce the number of rows in the array specified. Arrays are zero-based (the first element is zero) so you resize the array using a number that is one less than the number of elements you actually want. The number of parameters passed is the number of dimensions of the array being resized.

When you resize an array to -1, all rows are removed. It is faster to resize an array in this manner than to loop through the array and individually remove each row. You can use the array AddRow or AddRowAt methods to add rows or you can resize it again to the exact size you need.

When you ResizeTo an array to increase its size, any existing values in the array are retained.

When you resize an array to decrease its size, existing values are retained if they are still within the new array bounds.

Arrays can have a maximum index value of 2,147,483,646.

Sample Code

This example reduces the aNames array to 11 elements.

aNames.ResizeTo(10)

This example adds 10 elements to the aNames array

aNames.ResizeTo(aNames.LastRowIndex + 10)

This example reduces the aPeople array to 11 elements for the first dimension and 6 elements for the second dimension

aPeople.ResizeTo(10, 5)

When you resize an array with no bounds, its elements are removed. This is a fast way to clear out an array:

aNames.ResizeTo(-1)

See Also

Var statement; Arrays concept; ParamArray keyword; Operator_Redim, Operator_Subscript functions