-
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?
-
<?>
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