J
Joe Dunfee
I am attempting to use an array of arrays (ragged arrays), but am having
problems.
It seems the master-array elements must set equal to the sub-arrays only
AFTER the values are entered for the sub-arrays. Then it seems the values of
the elements are set and cannot be changed. Here is my sample
code with comments (my next question follows);
'==================
Sub ABC()
Dim vArr1(1 To 10) As Variant
Dim vArr2(1 To 5) As Variant
Dim vMainArr(1 To 2) As Variant
Dim lCounter As Long
Dim s As String, i As Long, j As Long
' Populate the sub arrays:
For lCounter = 1 To 10
vArr1(lCounter) = lCounter
If lCounter < 6 Then _
vArr2(lCounter) = lCounter * 2
Next lCounter
' Assign the sub arrays to the main array:
' Note that if this isn't done after are populated with values, the array
will be empty.
vMainArr(1) = vArr1
vMainArr(2) = vArr2
'change one of the elements as a test
vArr2(2) = 100 ' note that this change WON'T show in the vMainArr array
' Show the results
s = ""
For i = 1 To 2
For j = LBound(vMainArr(i), 1) To UBound(vMainArr(i), 1)
s = s & vMainArr(i)(j) & ","
Next j
s = s & vbNewLine
Next i
MsgBox s
End Sub
'==================
If my issues above are true, then I need to figure out a way around these
limitations. Note that my actual program would have perhaps 200 elements in
the main array, and 20 sub elements.of mixed type (strings and numbers), then
about 5 of the sub-sub elements would be 1-dimensional arrays. Just using 200
separate arrays would not be desirable.
Perhaps I must repeat the lines where sub arrays are assigned to the main
array EVERY time I change a value.
Any other suggestions?
Joe Dunfee
problems.
It seems the master-array elements must set equal to the sub-arrays only
AFTER the values are entered for the sub-arrays. Then it seems the values of
the elements are set and cannot be changed. Here is my sample
code with comments (my next question follows);
'==================
Sub ABC()
Dim vArr1(1 To 10) As Variant
Dim vArr2(1 To 5) As Variant
Dim vMainArr(1 To 2) As Variant
Dim lCounter As Long
Dim s As String, i As Long, j As Long
' Populate the sub arrays:
For lCounter = 1 To 10
vArr1(lCounter) = lCounter
If lCounter < 6 Then _
vArr2(lCounter) = lCounter * 2
Next lCounter
' Assign the sub arrays to the main array:
' Note that if this isn't done after are populated with values, the array
will be empty.
vMainArr(1) = vArr1
vMainArr(2) = vArr2
'change one of the elements as a test
vArr2(2) = 100 ' note that this change WON'T show in the vMainArr array
' Show the results
s = ""
For i = 1 To 2
For j = LBound(vMainArr(i), 1) To UBound(vMainArr(i), 1)
s = s & vMainArr(i)(j) & ","
Next j
s = s & vbNewLine
Next i
MsgBox s
End Sub
'==================
If my issues above are true, then I need to figure out a way around these
limitations. Note that my actual program would have perhaps 200 elements in
the main array, and 20 sub elements.of mixed type (strings and numbers), then
about 5 of the sub-sub elements would be 1-dimensional arrays. Just using 200
separate arrays would not be desirable.
Perhaps I must repeat the lines where sub arrays are assigned to the main
array EVERY time I change a value.
Any other suggestions?
Joe Dunfee