Results 1 to 6 of 6

Thread: [RESOLVED] A Collection of Collections - Setting an item

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Resolved [RESOLVED] A Collection of Collections - Setting an item

    This post is worded poorly. Please read post #2.


    I was given this code in a previous resolved thread:

    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
    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")?
    Last edited by deathfxu; May 11th, 2009 at 04:38 AM. Reason: clarification

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width