[RESOLVED] Problem with Redim Preserve
I'm getting a "Subscript out of range (Error 9)" on the 3rd line in the attached code.
The ReDim Preserve is in a loop where I need to add incremental rows to the array, the width will always stay constant at 10.
Any ideas what I'm doing wrong? (I know I've gotten this to work before, but can't see what I've done differently here)
Note: Option Base = 1
VB Code:
Dim MyArray() As Integer
'Later
ReDim MyArray(1, 10)
'Later still
ReDim Preserve MyArray(UBound(MyArray, 1) + 1, 10)
Re: Problem with Redim Preserve
Using an multi-dimensional array, you're only allowed to change the last dimension!
Allowed:
VB Code:
Dim MyArray() As Integer
.
.
ReDim MyArray(1, 10)
.
.
ReDim Preserve MyArray(1,UBound(MyArray, 1) + 1)
NOT Allowed:
VB Code:
Dim MyArray() As Integer
.
.
ReDim MyArray(1, 10)
.
.
ReDim Preserve MyArray(UBound(MyArray, 1) + 1,10)
Re: Problem with Redim Preserve
Thanks, I knew it was something stupid I was doing.
VB Code:
With DKenny
If .HoursAsleep < 3 Then
.Brain = False
End If
End With