Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Parent property of custom class

I have a custom class and one of its properties is another custom
class
Specifically I have a class which interfaces to an external
application to grab data, and a generic sub-class which works out
statistics.

pseudo-code...

set V = new clsCalItem

V.Stats.reset
while not finshed
V.stats.add
wend

msgbox V.stats.count, v.stats.mean

and clsCalItem contains the line
dim Stats as clsStats

My problem is that to get the current numerical value of V I would use
V.Value, but I can't see how to access the .Value method of V with
code inside clsStats.
What I want is basically to be able to use, inside the clsStats code a
line something like:

internalSum = internalSum + Me.Parent.Value

There is a very simple way round this, of course, I can change the
V.Stats.Add line to be V.Stats.Add(V.Value) but I would prefer the
elegance of the first version, and I am rather intrigued about whether
it is possible now. I can see myself wanting to write a .Parent
property in the future in situations where there isn't this
workaround. Surely classes often need to know who or what they are a
subclass of?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Parent property of custom class

One way is to tell the children who their parents are

' normal module
Sub Test3()
Dim c As New Class1
c.Name = "Sally"
End Sub

' code in Class1
Private msName As String
Private mChild As Class2
Public Property Let Name(sName As String)
msName = sName
Breed
mChild.MyParent
End Property
Public Property Get Name() As String
Name = msName
End Property
Sub Breed()
Set mChild = New Class2
Set mChild.Parent = Me
End Sub

' code in Class2
Private mother As Object ' or Class1 if known
Public Property Set Parent(obj As Object)
Set mother = obj
End Property
Public Sub MyParent()
MsgBox mother.Name
End Sub

Regards,
Peter T


"atpgroups" wrote in message
...
I have a custom class and one of its properties is another custom
class
Specifically I have a class which interfaces to an external
application to grab data, and a generic sub-class which works out
statistics.

pseudo-code...

set V = new clsCalItem

V.Stats.reset
while not finshed
V.stats.add
wend

msgbox V.stats.count, v.stats.mean

and clsCalItem contains the line
dim Stats as clsStats

My problem is that to get the current numerical value of V I would use
V.Value, but I can't see how to access the .Value method of V with
code inside clsStats.
What I want is basically to be able to use, inside the clsStats code a
line something like:

internalSum = internalSum + Me.Parent.Value

There is a very simple way round this, of course, I can change the
V.Stats.Add line to be V.Stats.Add(V.Value) but I would prefer the
elegance of the first version, and I am rather intrigued about whether
it is possible now. I can see myself wanting to write a .Parent
property in the future in situations where there isn't this
workaround. Surely classes often need to know who or what they are a
subclass of?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Parent property of custom class

On Dec 11, 2:15*pm, "Peter T" <peter_t@discussions wrote:
One way is to tell the children who their parents are


<Snip Code

OK, I can see that that would work. Is there any risk of a loop? My
first thought with your method was to tell the child who its parent is
in the Class_Initialize event of the parent.
The problem there is that when the Child creates an object (obj in
your example) then that code will run again, because obj has a child.

I think I will save my work before trying this...
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Parent property of custom class

On Dec 11, 6:12*pm, atpgroups wrote:

The problem there is that when the Child creates an object (obj in
your example) then that code will run again, because obj has a child.


OK, it seems not to be a problem. The code runs through only
once.There is an infinitely deep logical tree in the Watch window, but
that isn't a problem.

Thanks.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing value of Node.Parent destroys .Bold property of entireancestry. [email protected] Excel Programming 1 May 4th 08 09:12 PM
Get Property value of class instance by passing string property name [email protected] Excel Programming 2 October 19th 07 05:47 PM
Parent Properties in Custom Classes J Streger Excel Programming 1 March 28th 07 12:15 AM
Excel VBA Class Objects - Parent & Successor Objects [email protected] Excel Programming 1 January 15th 07 12:06 AM
the Parent property mrmack Excel Programming 3 July 13th 06 04:55 AM


All times are GMT +1. The time now is 04:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"