Putting an array into an array

  • Thread starter Thread starter Matthew
  • Start date Start date
M

Matthew

I have a project that would work better if I could put an
array inside another array...Is that possible? Have a
kind of parent array in which every record has a number of
records inside it (not always being the same number of
records).
 
Piggy-backing on your post, Doug, because I'm not seeing Matthew's original
post ...

I can't think of a way of implementing an array of arrays either, but
perhaps a collection of arrays might work?

Public Sub CollectionOfArrays()

Dim lngLoopArray As Long
Dim lngLoopCollection As Long

Dim col As Collection

Dim astrOne(3) As String
Dim astrTwo(4) As String
Dim astrTemp() As String

For lngLoopArray = LBound(astrOne) To UBound(astrOne)
astrOne(lngLoopArray) = CStr(lngLoopArray) & "A"
Next lngLoopArray
For lngLoopArray = LBound(astrTwo) To UBound(astrTwo)
astrTwo(lngLoopArray) = CStr(lngLoopArray) & "B"
Next lngLoopArray

Set col = New Collection
col.Add astrOne, "1"
col.Add astrTwo, "2"

For lngLoopCollection = 1 To 2
astrTemp = col(CStr(lngLoopCollection))
For lngLoopArray = LBound(astrTemp) To UBound(astrTemp)
Debug.Print astrTemp(lngLoopArray)
Next lngLoopArray
Next lngLoopCollection


End Sub

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
I have a project that would work better if I could put an
array inside another array...Is that possible? Have a
kind of parent array in which every record has a number of
records inside it (not always being the same number of
records).

If you use a variant array, then you can put it into any variable that can
hold a variant, including an array element:


Dim a_varOuter as Variant

Dim a_varInner as Variant

a_varOuter = Array("Monday", "Tuesday", "Wednesday")

a_varInner = Array("Breakfast", "Lunch", "Dinner")

a_varOuter(1) = a_varInner


But you do, of course, lose the information in the old element ("Monday").
There is no sense in which this is a heirarchy structure. Can I ask why you
don't just use a couple of joined tables anyway?

HTH


Tim F
 
Back
Top