This post is worded poorly. Please read post #2.
I was given this code in a previous resolved thread:
I am using the wrong syntax on the bold line. Does anyone know how I am supposed to do that if I do not know the index number, and only know the key ("ninja")?Code:Option Explicit Dim A As Collection Sub Form_Load() InitColls End Sub Sub InitColls() Dim B As Collection Dim C As Collection Dim D As Collection Set A = New Collection Set B = New Collection Set C = New Collection Set D = New Collection A.Add Item:=B, Key:="B" A.Add Item:=C, Key:="C" B.Add Item:=D, Key:="D" End Sub Sub Command1_Click() Dim n As Long If A Is Nothing Then InitColls Debug.Print A.Count Debug.Print A(1).Count Debug.Print A(2).Count Debug.Print A(1)(1).Count Debug.Print "---------------" n = A("C").Count + 1 A("C").Add Item:="Item C" & n n = A("B")("D").Count + 1 A("B")("D").Add Item:="Item D" & n, Key:="ninja" Debug.Print A.Count Debug.Print A(1).Count Debug.Print A(2).Count Debug.Print A(1)(1).Count Debug.Print "---------------" n = A("B")("D").Count Debug.Print A("B")("D")(n) n = A("C").Count Debug.Print A("C")(n) Debug.Print "---------------" A("B")("D").Item("ninja") = "woot woot!" Debug.Print A("B")("D")("ninja") End Sub




Reply With Quote