Results 1 to 2 of 2

Thread: Subsrcipt out of Range

  1. #1

    Thread Starter
    Member
    Join Date
    May 2002
    Posts
    41

    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

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    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
  •  



Click Here to Expand Forum to Full Width