473,396 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using array without knowing its size

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
3 1369
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
5
by: Matthew Jakeman | last post by:
Hi, if i define an int array globally as follows : int test ; Is it possible to set the size of this array inside a function later in the code ? TIA Matt
30
by: questions? | last post by:
say I have a structure which have an array inside. e.g. struct random_struct{ char name; int month; } if the array is not intialized by me, in a sense after I allocated a
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
14
by: mast2as | last post by:
Hi everyone, I am trying to implement some specs which specify that an array of parameter is passed to a function as a pointer to an array terminated by a NULL chatacter. That seemed fairly easy...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
15
by: Madhur | last post by:
Hi All, I would like you help me in creating an array of data types. I am interested in look at the the data type which looks like this Array...
37
by: Richard Heathfield | last post by:
candide said: They aren't. An array is an array. An address is a pointer value. These are not the same thing. If you mean that &array and &array are the same, they aren't. They have different...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.