# REDIM Re-Dimension Array

> Source: https://manual.pvxplus.com/directives/redim

## Formats

|  |  |  |
| --- | --- | --- |
| 1\. | *Re-dimension Array*: | **REDIM** *array_name* **\[**$**\]** (*subscript_1*\[,*subscript_2*\[,*subscript_3*\]\]) |
| 2\. | *Insert Array Indices*: | **REDIM INSERT** *array* **\[**$**\]** \[*index*:*count* **\]** |
| 3\. | *Delete Array Indices*: | **REDIM DELETE** *array* **\[**$**\]** \[*index*:*count* **\]** |

***Where:***

|  |  |
| --- | --- |
| *array_name*\[*$*\] | Numeric or string variable to be dimensioned as an array. |
| *subscript_1* | 1st dimensions (*minimum:maximum*) of array. Numeric expression, integers. |
| *subscript_2* | 2nd dimensions (*minimum:maximum*) of array. Numeric expression, integers. |
| *subscript_3* | 3rd dimensions (*minimum:maximum*) of array. Numeric expression, integers. |
| *array* | String or numeric array. |
| *index*:*count* | Numeric index at which the element or range of elements will be inserted or deleted. If *count*is omitted, it will default to 1. Multiple dimensions could be specified as:<br>```<br>     REDIM INSERT array [index:count, index:count, index:count<br>]<br>     REDIM DELETE array [index:count, index:count, index:count<br>]<br>```<br>For array dimensions that you do not want changed, set *count* to zero. |

## Description

The **REDIM** directive is used to re-dimension an array without destroying data already contained within the array. All existing data is preserved in the exact same location within the re-dimensioned array. This directive will work on string or numeric arrays.

The **REDIM INSERT** directive is used to insert either a single element at the specified index or a range of elements.

The **REDIM DELETE** directive is used to delete the specified index or range of indices.

Note:  
Data in array elements that do not exist in the re-dimensioned array are discarded.  
  
The REDIM INSERT and REDIM DELETE directives do not work on associative arrays and will generate errors if the insertion/deletion index does not exist or if you attempt to delete elements that do not exist.

*(The REDIM INSERT and REDIM DELETE directives were added in PxPlus 2021.)*

## See Also

**[DIM Define Arrays and Strings](https://manual.pvxplus.com/directives/dim)  
[DIM( ) Generate String/Get Array Size](https://manual.pvxplus.com/functions/dim)**

## Example

```
dim X[1:10]
X[5]=5,X[6]=6
redim X[-5:20,4]
```

X\[5,0\] has 5 and X\[6,0\] has 6 because the default second index is 0; i.e. the original dimension was effectively the same as X\[1:10,0:0,0:0\].
