PDA

View Full Version : Can One Class Hold Many Objects



SamT
03-22-2013, 12:08 AM
I want to

Set MyObject = New MyObjectClass
Set SubObject = New MyObject.SubObject_Class-a-thoid
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

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



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

Aflatoon
03-23-2013, 06:36 AM
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.

Paul_Hossler
03-23-2013, 07:01 AM
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

SamT
03-23-2013, 11:47 AM
Thanks Paul,

I Dl'ed all that.

SamT

SamT
03-23-2013, 11:48 AM
Aflatoon,

Thanks for the ideas.

SamT