|
-
May 31st, 2002, 04:08 PM
#1
Thread Starter
Member
Subsrcipt out of Range
I have followed Karls tutorial on Arrays and still have some quesrtions. I can not get the dynamic array to work like your example. Thanks for any information. Also, can you test for a NULL record in the array so you know how many elements were used?
Private Sub btnFlowIt_Click()
Dim MyArray() As String
i = 0
MyArray(i) = strData (I get the dreaded subscript out of range here )
i = 1 + 1
ReDim Preserve MyArray(1 To i + 1)
For i = LBound(MyArray) To UBound(MyArray)
MsgBox MyArray(i)
Next i
End Sub
Jim
-
May 31st, 2002, 04:41 PM
#2
Frenzied Member
You have to ReDim the array to some size before assigning a value to an element of the array.
Your entire snippet of code makes no sense.
You first attempt to store a string in element 0 which hasn't been Dimmed.
i = 1 + 1, so i = 2 and the ReDim will Dim the array with elements 1 to 3. What about element 0 which you tried to assign a value to?
Then you attempt to display the element values when nothing has been stored in them.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|