Reputation: 9
I don't understand some parts in the following code:
For i = 2 To UBound(a, 1)
txt = Join$(Array(a(i, 3), a(i, 4)), Chr(2))
If Not dic.exists(txt) Then
Set dic(txt) = CreateObject("Scripting.Dictionary")
End If
dic(txt)(a(i, 1)) = VBA.Array(a(i, 5), a(i, 6), a(i, 2))
Next
Thanks alot
Upvotes: 0
Views: 66
Reputation: 54807
Loop through the elements of the 1st dimension (rows) of a multi-dimensional array (a
):
For i = 2 To UBound(a, 1)
Revealing that a
is a 2D array, joining the elements of columns 3 and 4 into a string (txt
).
txt = Join$(Array(a(i, 3), a(i, 4)), Chr(2))
or to simplify:
txt = a(i, 3) & Chr(2) & a(i, 4)
Checking if txt
exists as a key in the existing dictionary (dic
).
If Not dic.exists(txt) Then
End If
If it doesn't, add a new dictionary as an item associated with the current key:
Set dic(txt) = CreateObject("Scripting.Dictionary")
txt
,Use the value in the first column of the array (a
) as the key in the new dictionary and add a zero-based (VBA.
ensures zero-based) array with the values from columns 5, 6, and 2 of array a
as the associated item to the new dictionary (of course only if the 1st column value does not already exist in the 'new' (inner) dictionary):
dic(txt)(a(i, 1)) = VBA.Array(a(i, 5), a(i, 6), a(i, 2))
dic:
txt
a(i, 1)
VBA.Array(...)
Upvotes: 1