By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,639 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,639 IT Pros & Developers. It's quick & easy.

Using array without knowing its size

P: n/a
When using an array - and you initially don't know many "records" it
is to hold - how is the proper way of dimensioning it?

In my previous thread I'm looping folders. Let's say these are to be
put into an array. Initially I don't know the number of folders being
returned, so how would i dimension the array properly?

I've learned that ReDim is somewhat ressource-eating, but maybe that
is the way to go in the given scenario?
Regards /Snedker
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
If, as with my reply above, you use an ArrayList, then the array will
dynamically resize itself. All you do is "Add" items to it. When you are
done, you can look at "Count" property to see how many items you have
collected. ArrayLists are waaaay more efficient in this scenario than any
kind of "ReDim".

"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:tb********************************@4ax.com...
When using an array - and you initially don't know many "records" it
is to hold - how is the proper way of dimensioning it?

In my previous thread I'm looping folders. Let's say these are to be
put into an array. Initially I don't know the number of folders being
returned, so how would i dimension the array properly?

I've learned that ReDim is somewhat ressource-eating, but maybe that
is the way to go in the given scenario?
Regards /Snedker

Nov 21 '05 #2

P: n/a
Morten,

Don't try to use a fixed array when you don't know for sure that it is
always fixed or have absolutly to use it.

There are so many arrays and collections in VBNet and you can make them even
yourself.

In my opinion is the most simplest one (the first to choose) is the one as
Robin told as well the ArrayList.

Cor
Nov 21 '05 #3

P: n/a
If you still need an array, you can always call ReDim once the ArrayList is
filled and copy the records over. Since you are just copying pointers, it
shouldn't be costly.

--
Jonathan Allen
"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:d7*******************@news.demon.co.uk...
If, as with my reply above, you use an ArrayList, then the array will
dynamically resize itself. All you do is "Add" items to it. When you are
done, you can look at "Count" property to see how many items you have
collected. ArrayLists are waaaay more efficient in this scenario than any
kind of "ReDim".

"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:tb********************************@4ax.com...
When using an array - and you initially don't know many "records" it
is to hold - how is the proper way of dimensioning it?

In my previous thread I'm looping folders. Let's say these are to be
put into an array. Initially I don't know the number of folders being
returned, so how would i dimension the array properly?

I've learned that ReDim is somewhat ressource-eating, but maybe that
is the way to go in the given scenario?
Regards /Snedker


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.