Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReDim Preserve error

I am trying to redim preserve a two dimensional array. at the very top of my code I have:

Dim BayQuestionArray() As Variant
Dim numberofbay As Double

I have two buttons, the first button is for initializing the array size:

numberofbay = 1
ReDim Preserve BayQuestionArray(numberofbay, 37)

and the second button is for upsizing the array

ReDim Preserve BayQuestionArray(numberofbay + 1, 37)

The second button doesn't work, it keeps giving me an error saying Run time error 9 Subscript out of range. Why?

like image 817
HumanlyRespectable Avatar asked Nov 29 '25 06:11

HumanlyRespectable


1 Answers

When using Preserve to resize an array variable (declared as such, not as Variant), you may only alter the upper boundary of the last dimension. You would need to transpose your array, or use a jagged array or other structure like a Dictionary/Collection.

like image 165
Rory Avatar answered Dec 02 '25 03:12

Rory



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!