Consulting

Results 1 to 5 of 5

Thread: Can One Class Hold Many Objects

  1. #1
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location

    Can One Class Hold Many Objects

    I want to
    [vba]
    Set MyObject = New MyObjectClass
    Set SubObject = New MyObject.SubObject_Class-a-thoid[/vba]
    Is it possible? Brief idea how?

    I'm building a system that has many "objects," very hierarchical in shape. The system has to loop thru from the top to the bottom of the hierarchy. The Bottom of the pyramid is made up of sets of a dozen or so "properties." The second level up will have one to several dozen sets of maybe a dozen "Properties." The third shrinks to less than a dozen set of a dozen or so "Properties." Next to the top is less than a dozen sets of few "Properties." There can be only one at the top.

    Each "Object" and Property will have one "Item" that consists of a unique ID that references Xl tables and all Functions and Procedures will be fed those "Object" and "Properties" as arguments, then will use the IDs to determine Variable Values.

    The physical object in the system are many Servers with many Paths to many Workbooks with many Worksheets and many Reports.

    I will have one three dimensional XL table consisting of many Reports (Sheets) referring to many Sheets (Rows) on many books (Columns.) There will also be an Indices Workbook holding Indexes of paths and other system constants and variables.

    The Master Book will do all the work. I need to do things like
    [vba]
    For a = 1 to Book.Count
    For z = 1 to Books(a)Sheets.Count
    For b = 1 to Sheets(z).Count
    'where a,b,y, and z are identical in value to indices which refer to physical objects.
    Loopy-da-loops
    [/vba]


    I am considering using several hierarchical UDTs made up of even more UDTs made up of ....
    Also, hierarchical Arrays, Dictionaries, and collections of Arrays, Dicts, and collections

    What are the Pros and cons of each.

    Primary concern is ease of understanding and maintenance, scondary is speed, tertiary is memory.

    Thanks

    SamT
    Last edited by SamT; 03-22-2013 at 01:06 AM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Yes - use a Collection (or array or dictionary as you wish) in the parent class to hold the children objects. You can repeat the same down through the hierarchy, just like Excel's object model.
    Be as you wish to seem

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    SamT --

    I had a reference file on my HD from XLD

    http://www.vbaexpress.com/forum/showthread.php?t=37125

    that has a collection of collections that you might look at

    I converted it (mostly as an learning experience) to use dictionaries and it worked out well (for me at least)

    What I found interesting was how to use _NewEnum to For Each/Next through a collection

    Paul

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Thanks Paul,

    I Dl'ed all that.

    SamT
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Aflatoon,

    Thanks for the ideas.

    SamT
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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