Collection vs. Array of Arrays, nszim
...the drawback to using a collection
is that you can't (directly) change the data
Just an idea. For more complicated tasks, I like to use a Dictionary.
Here's a small demo. Not sure if this is what the Op wants though.
Note that the arrays are zero based.
Sub Demo()
'// Dana DeLouis
Dim d, t
Set d = CreateObject("Scripting.Dictionary")
d.Add 1, Array(Array(11, 12, 13), Array("Alpha", "Beta", "Charlie"))
d.Add 2, Array(Array(21, 22, 23), Array("Delta", "Echo", "Foxtrot"))
'// Change "Charlie" to "Zulu"
t = d(1)
t(1)(2) = "Zulu"
d.Item(1) = t
'// To check...
t = d(1)
End Sub
--
HTH. :)
Dana DeLouis
Windows XP, Office 2003
"keepITcool" wrote in message
.com...
Jim,
as explained in my post the drawback to using a collection
is that you can't (directly) change the data once inside the collection.
Alternative is a user defined type....
Option Explicit
Type MyType
IntArray() As Integer
StrArray() As String
End Type
Sub Test()
Dim i%
'UserType
Dim uTest As MyType
With uTest
ReDim .IntArray(5)
ReDim .StrArray(10)
For i = LBound(.IntArray) To UBound(.IntArray)
.IntArray(i) = i
Next
For i = LBound(.StrArray) To UBound(.StrArray)
.StrArray(i) = i
Next
End With
Call ModifyType(uTest)
'Collection
Dim col As Collection
Set col = New Collection
col.Add uTest.IntArray, "int"
col.Add uTest.StrArray, "str"
Call ModifyCol(col)
End Sub
Sub ModifyType(uIS As MyType)
'Can change data in the defined type's array
uIS.IntArray(3) = 999
Debug.Print uIS.IntArray(3); "<< s/b 999"
End Sub
Sub ModifyCol(col As Collection)
'Cant change data inside a collection..
col("int")(3) = 111
Debug.Print col("int")(3); "<< s/b 111 but isnt"
End Sub
|