Collections vs Arrays

P

Pete

I am working on an app that can have as many as 50 string arrays where
each array can have 1-50 elements. I could manually create all or the
arrays and controllthem individually. However, I would like to not
hard code this, it might change. I have been reading about
Collections and got to wondering if the app would be better off using
a collection.

First, is it possible to create a collection that contains upto 50
arrays? If so, would someone please give a sample code snippet? I am
new to this effort.

Can each array in the collection be "redim"ed allow for the variable
number of rows?
 
T

Tony Toews [MVP]

Pete said:
I am working on an app that can have as many as 50 string arrays where
each array can have 1-50 elements.

What type of data would you be tracking in those 50 arrays.
First, is it possible to create a collection that contains upto 50
arrays? If so, would someone please give a sample code snippet? I am
new to this effort.

Can each array in the collection be "redim"ed allow for the variable
number of rows?

I very much doubt it

Why not just use a 2 dimensial array and dim it as 50 x 50 right from the start?

Even if there are 1024 bytes in each variable that's only 2.5 Mb of memory consumed.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
P

Pete

What type of data would you be tracking in those 50 arrays.



I very much doubt it

Why not just use a 2 dimensial array and dim it as 50 x 50 right from the start?

Even if there are 1024 bytes in each variable that's only 2.5 Mb of memory consumed.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems athttp://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog -http://msmvps.com/blogs/access/

I keeping track of key data for records in the array. For example, on
record will point to another record in which there may be additional
pointers to additional records. The pointers may or may not exist and
may be numerous. In essience it is a tree structure starting with a
single record an having multiple limbs with multiple leaves.

Can individual subarrays be "redim"ed in the two-dimension array? I
have atttempted this and appear to be getting an error. I may be
creating the error.
 
M

Matthias Klaey

Pete said:
I keeping track of key data for records in the array. For example, on
record will point to another record in which there may be additional
pointers to additional records. The pointers may or may not exist and
may be numerous. In essience it is a tree structure starting with a
single record an having multiple limbs with multiple leaves.

Can individual subarrays be "redim"ed in the two-dimension array? I
have atttempted this and appear to be getting an error. I may be
creating the error.

Use variant arrays. For example:

Option Base 1 ' just to make counting easier

Dim vPointers As Variant
Dim vRow As Variant

vPointers = Array()
Redim Preserve vPointers(2)
vRow = Array(1, 3, 5)
vPointers(1) = vRow
vRow = (2, 3, 4, 5, 6)
vPointers(2) = vRow

? vPointers(1)(2) ' -> 3
? vPointers(2)(4) ' -> 5
Redim Preserve vRow(10)
vRow(9) = 1818
vPointers(2) = vRow
? vPointers(2)(9) ' -> 1818

HTH
Matthias Kläy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top