?
Solved

Using ParentClass Builder with curious results

Posted on 2011-05-02
12
Medium Priority
?
504 Views
Last Modified: 2012-05-11
I want to point out a curiosity in the naming convention being used.

Note,  the naming from autosense:

Sub test()
Dim myRef_Collection As New cRefineries 'instantiates the collection
Dim myRefinery As cRefinery

    myRef_Collection.Add "Valero" 'Name field is the default field
    myRef_Collection(1).RefineryDetails.Add "Crude"
    myRef_Collection(1).RefineryDetails(1).cRefineryStatistic.Add "Marlim"
    myRef_Collection(1).RefineryDetails(1).cRefineryStatistic(1).cRefineryDataPoint.Add "1Q03"
    myRef_Collection(1).RefineryDetails(1).cRefineryStatistic(1).cRefineryDataPoint(1).DataPoint = 5

End Sub



I created each Parent/Child using http:/A_3802.html with the same naming convention:

cRefineryDetails->cRefineryDetail

cRefineryStatistics->cRefineryStatistic

cRefineryDataPoints->cRefineryDatapoint

and yet, RefineryDetails (not cRefineryDetails) is the collection under myRef_colleciton

also, cRefineryStatistic (not cRefineryStatistics) is for the next, and so- on


So, why did the first not have a "c" in front of it, and why the others have the "c" and why the first is plural and the rest are not is boggling....

I created the classes 3 times for practice with the same results.


Attached, a redacted version of the app I'm working on...

Cheers,

Dave
0
Comment
Question by:dlmille
  • 6
  • 4
  • 2
12 Comments
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 35508827
Dave,

I think you left off the attachment :)

Patrick
0
 
LVL 42

Author Comment

by:dlmille
ID: 35508835
I guess I did!

Here it is...

Dave
Example-File.xlsm
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 35508901
Dave,

I am heading to the airport now, and may not get a chance to look at it until tomorrow morning.

If any other Experts care to jump in, by all means please do so.

Patrick
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 42

Author Comment

by:dlmille
ID: 35508912
No worries - its not holding up my work, but messing with my head, lol

Thanks,

Dave
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 1600 total points
ID: 35509242
Dave,

Sitting in the airport lounge, so I cannot actually view the code right now.

Part of it, I suspect, is that you're not yet clear on the distinction between a class and a class property/method that returns an instance of a class.

if we get wifi on the plane perhaps I will take a look at the file :)
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 400 total points
ID: 35517751
Dave,

Please award Patrick's comment above as I am simply assisting in confirming since he is traveling.  Note that in the cRefinery class you have this bit of code:
Property Get RefineryDetails() As cRefineryDetails
    
    ' Returns reference to item's cRefineryDetails collection
    
    ' Read-only
    
    Set RefineryDetails = Safe_RefineryDetails
    
End Property

Open in new window


As you can see that is a property called RefineryDetails.  The cRefineryDetails is name of class whereas RefineryDetails is name of property as Patrick eluded to.  In your code, you are grabbing hold of a specific instance of cRefinery and so what you are seeing is the properties of that class namely Name and RefineryDetails.

Likewise, you will find the following property definition in the cRefineryDetail class:
Property Get cRefineryStatistic() As cRefineryStatistics
    
    ' Returns reference to item's cRefineryStatistics collection
    
    ' Read-only
    
    Set cRefineryStatistic = Safe_cRefineryStatistic
    
End Property

Open in new window


These properties can be named whatever of course; therefore, simply rename these as you wish.  

Hope that helps!
0
 
LVL 42

Assisted Solution

by:dlmille
dlmille earned 0 total points
ID: 35611153
I think I get parent class and property/method as the attached code I shared demonstrates that.  My query was around the naming that was created, and I need to rebuild it again to see if perhaps I mistyped the names of the parent/child/and property's.

I would have assumed, as with RefineryDetails, each subordinate child being a collection would have had the same naming convention...

Namely:

RefineryDetails(i).RefineryStatistics(j).RefineryDetails(k).RefineryDataPoints(l).dataPoint  SHOULD have been the way it was setup.

So.... after about 10 minutes.... I redid the Parent-Class builder exercise, this time paying a bit more attention.

The problem was my naming of the "Next Level Property Name".  For some reason that didn't come out as strongly in the article, for me, anyway.  I was following the steps verbatim and missed "Weeks" instead of clsWeeks was the next level name in the example.

So, now, I built the structure like this - with more care:

 Builder steps
And the code now looks like this:

 
Sub test()
Dim myRef_Collection As New cRefineries 'instantiates the collection
Dim myRefinery As cRefinery

    myRef_Collection.Add "Valero" 'Name field is the key property
    myRef_Collection(1).RefineryDetails.Add "Crude" 'Field is the key property
    myRef_Collection(1).RefineryDetails(1).RefineryStatistics.Add "Marlim" 'Statistic is the key property
    myRef_Collection(1).RefineryDetails(1).RefineryStatistics(1).RefineryDatapoints.Add "1Q03" 'QtrYr is the key property
    myRef_Collection(1).RefineryDetails(1).RefineryStatistics(1).RefineryDatapoints(1).DataPoint = 5

End Sub

Open in new window


Which "makes more sense" to me.

The attached example is what I ended up with, having added datapoint to the cRefineryDataPoint class.

All's well that ends well.  Actually taking pictures and setting them aside in Powerpoint, seeing how the all laid out helped quite a bit.  I had written my structure right on top of the printed article, but it was the "Next Level" name, naming convention I just couldn't shake free in my head, till now.

Patrick, thanks to your article:  http:/A_3802.html, this exercise was not as daunting.  I was building the structure the "old" way, using Types and I was building a bunch of dynamic arrays in my types of types, etc., and turns out my intuition to move to objects was right, and your Parent Class builder was VERY timely.

I may have some questions about the code that was generated at some future date, as I use this approach again in new projects - as I need to dig into the code that was generated a bit to understand the basics as if I could have built the generated code from scratch, lol - for more understanding.

Very neat - one of my first out-of-college assignments was CASE development and translations, so I appreciate code generators.  Nice to have this generate for you and not get in the weeds, deal with type-o's, etc., (though I guess my miss on the next level property is not really a type-o, as the brain didn't have true understanding, lol).

This exercise has also given me a better understanding of objects and collections of objects that our out there, that we use everyday.


Nice!

Dave
Example-File2.xlsm
0
 
LVL 42

Author Comment

by:dlmille
ID: 35611502
>>not yet clear on the distinction between a class and a class property/method

Given a read through what I just posted, I have to agree.  Getting there...

Cheers,

Dave
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 35689923
Glad to help, Dave!
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 35692527
Yes, glad to help and thank you for the very nice summarizing post.  It not only helps you clarify for us what you found, but will be immensely helpful to those reading in the future who may have missed the sublte point on the property naming.  Very well done!

Patrick, a pleasure as usual.

Dave, thanks for the assisted points.

Regards,

Kevin
0
 
LVL 42

Author Comment

by:dlmille
ID: 35694266
Well, I appear to be in "article writing mode" having just written my second (still waiting on an editor to pick up this neglected child, :).

Thanks,

dave
0
 
LVL 42

Author Closing Comment

by:dlmille
ID: 35714933
Thanks for the comments, pushing me in the right direction - after having restarted the builder several times, I slowed down a bit and with your comments in the back of my head, constructed the structures "more properly" and correct!

Cheers,

Dave
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question