Results 1 to 2 of 2

Thread: proper way to make a dynamic array?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2000
    Posts
    70

    Question

    Hey Guys.. i'm trying to make a dynamic array in one of my modules, i use in declarations:
    Code:
    Private PathsToExplore() As String
    and then when i try to add items to it from within that module i get subscript out of range errors.
    i've tried adding as index 0, and as index 1, i have also tried dim'ing it as Public. It works fine if i make it:
    Code:
    Private PathsToExplore(1 to 1000) As String
    but i dont want to have a fixed size array because my array size may change dramatically and i dont wish to waste space. also i cycle through the array to UBound() of it, and if i dim it to 1000 or so, it takes a lot longer if i have just a few items in it, but as i said the size can change dramatically.. any ideaS?
    Daniel Rose
    VB 5.0 Enterprise.
    irc:irc2.dynam.ac

    If TheCodeInTheSig() Is Not Lame() Then IDontKnowWhatIs()

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    You can use Redim/Redim Preserve for an array.
    Dim PathsToExplore() As String
    Redim PathsToExplore(0 to 100) as String
    gives you a new array of fixed length
    or
    you you can preserver and redim as you go.
    
    For i = 1 to 500
      Redim Preserve PathsToExplore(i)as String
      PathsToExplore(i) = "Whatever"
    Next i
    
    
    
    To be sure you stay in bounds use
     For i = LBound(PathsToExplore) to UBound(PathsToExplore)
        List1.AddItem PathsToExplore(i)
     Next i
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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