Keyword

# Redim

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Resizes the specified array. Arrays are zero-based.

## Usage

``` xojo
Redim arrayName (newSize1 [, newSize2, ... newSizeN ])
```

| Part      | Type                               | Description                                                                                                                                                                                                        |
|-----------|------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| arrayName | n/a                                | The name of any previously declared array.                                                                                                                                                                         |
| newSize1  | `Integer</api/data_types/integer>` | The new size for the array. Use -1 to create an unbounded array, which removes all the array elements. Resizing the array to less than -1 causes an `OutofBounds</api/exceptions/outofboundsexception>` exception. |
| newSizeN  | `Integer</api/data_types/integer>` | The new size for the Nth dimension of the array.                                                                                                                                                                   |

## Notes

<span class="title-ref">Redim</span> exists for Visual Basic compatibility only. Use `Arrays.ResizeTo<arrays.resizeto>` instead.

The <span class="title-ref">Redim</span> method is used to increase or reduce the number of elements 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 <span class="title-ref">Redim</span> an array with no bounds (-1) then all its elements are removed. It is faster to <span class="title-ref">Redim</span> an array in this manner than to loop through the array and individually remove each value. You can use the array `Add<arrays.add>` or `Arrays.AddAt<arrays.addat>` methods to add elements or you can <span class="title-ref">Redim</span> it again to the exact size you need.

When you <span class="title-ref">Redim</span> an array to increase its size, any existing values in the array are retained.

When you <span class="title-ref">Redim</span> an array to decrease its size, existing values are retained if they are still within the new array bounds.

All arrays are indexed starting at position 0. Arrays can have a maximum index value of 2,147,483,646.

## Sample code

This example reduces the aNames array to 11 elements.

``` xojo
Redim aNames(10)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This example adds 10 elements to the aNames array

``` xojo
Redim aNames(aNames.Lastindex + 10)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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

``` xojo
Redim aPeople(10, 5)
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When you <span class="title-ref">Redim</span> an array with no bounds, its elements are removed. This is a fast way to clear out an array:

``` xojo
Redim aNames(-1)
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

`Var</api/language/var>` statement; `Arrays</api/language/arrays>` concept, `String.FromArray<string.fromarray>`, `String.Split<string.split>` functions; `ParamArray</api/language/paramarray>` keyword; `Operator Redim</api/language/operators/operator_overloads/operator_redim>`, `Operator Subscript</api/language/operators/operator_overloads/operator_subscript>` functions

</div>
