# Set array size by a variable

**URL:** <https://forum.xojo.com/t/set-array-size-by-a-variable/15970>\
**Category:** Getting Started\
**Created:** [April 24, 2014, 7:32am UTC](https://forum.xojo.com/t/set-array-size-by-a-variable/15970 "2014-04-24T07:32:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Sthler](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/f19dbf/32.png) [@Peter\_Sthler](https://forum.xojo.com/u/Peter_Sthler)\
**Post date:** [April 24, 2014, 7:32am UTC](https://forum.xojo.com/t/set-array-size-by-a-variable/15970/1 "2014-04-24T07:32:14Z")

</div>

Hi,

i want to size an array according to the value of a variable … and it doesn’t really work …  
My code looks like :

dim intLebensdauer as Integer  
intLebensdauer=50  
dim dblInvest(intLebensdauer) as Double

and i only get the error-message: “The size of an array must be a constant or number”. OK … it’s not constant … but it is a number … ?

What am i doing wrong?  
Thanks very much for your assistance

Peter

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [April 24, 2014, 7:34am UTC](https://forum.xojo.com/t/set-array-size-by-a-variable/15970/2 "2014-04-24T07:34:19Z")

</div>

`dim intLebensdauer as Integer
intLebensdauer=50
dim dblInvest() as Double
ReDim dblInvest(intLebensdauer)`

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cowgar](https://forum.xojo.com/user_avatar/forum.xojo.com/jeremy_cowgar/32/4590_2.png) [@Jeremy\_Cowgar](https://forum.xojo.com/u/Jeremy_Cowgar)\
**Post date:** [April 24, 2014, 7:39am UTC](https://forum.xojo.com/t/set-array-size-by-a-variable/15970/3 "2014-04-24T07:39:46Z")

</div>

On the same subject matter, to clear the array of all elements:

```auto
ReDim dblInvest(-1)
```

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:11pm UTC](https://forum.xojo.com/t/set-array-size-by-a-variable/15970/4 "2020-10-29T17:11:44Z")

</div>


