How to access a property of the PARENT custom class instance from a CHILD
custom class instance.
Simply as a convenience for discussion ... let's assume
A Mammal has teeth
Teeth are an array of Tooth's
From inside one instance of the TOOTH class ...
... how do I get access to a property (Carnivore) in the
MAMMAL class?
'-------------------------------------------------------------
Public Class Mammal
Private myTeeth As New Teeth()
Public Sub New()
End Sub
Private pCarnivore As Boolean = False
Public Property Carnivore() As Boolean
Get
Return pCarnivore
End Get
Set(ByVal value As Boolean)
pCarnivore = value
End Set
End Property
End Class
'-------------------------------------------------------------
Public Class Teeth
Private myTooth() As Tooth
Public Sub New()
End Sub
End Class
'-------------------------------------------------------------
Public Class Tooth
Public Sub New()
End Sub
Private pLngth As Integer
Public Property Lngth() As Integer
Get
Return pLngth
End Get
Set(ByVal value As Integer)
pLngth = value
End Set
End Property
===================
so right here ...
inside this instance of Tooth class ...
... how can I discover if the parent Mammal is a
Carnivore?
===================
End Class
'-------------------------------------------------------------

Signature
F.V.
Ralph - 23 Feb 2009 22:56 GMT
> How to access a property of the PARENT custom class instance from a CHILD
> custom class instance.
A Parent/Child relationship is an association which is usually only known by
the Parent. If a Child needs to have a parent, or know it's parent, to do
its job then this information needs to be supplied to the Child by the
Parent when the association is implemented.
A broad example would be controls (that have a 'parent' property) that are
placed in a frame with a Dialog or Form editor. The editor sets the
control's 'parent' property during design.
But in any case you are using vb.net, and this newsgroup is for users of
classic VB (VB6 or lower). You will have better success if you post your
question to a dotNet newsgroup. They all have ".dotnet." in the title.
-ralph
Nutter327 - 21 Apr 2009 22:13 GMT
Flash:
Try the following:
Add a property to the "child" classes named parent.
Example:
Public Property Parent() as mammal
get
return pParent
end get
set(obj as mammal)
set pParent = obj
end set
end property
Then in the initialize event of the mammal class add:
me.myteeth.parent = me
Forgive me if some syntax needs tweeked, but it works for me in vba.
Hope I helped!
MikeD - 21 Apr 2009 23:55 GMT
> Flash:
>
[quoted text clipped - 17 lines]
>
> Hope I helped!
Probably just confused him more. That's not even CLOSE to being code
that'll work in VBA. Looks more dotnet-ish than anything else.
Plus, the question was posted 2 months ago and no reply from the OP to the
one reply he did get....not likely he's still checking for additional
replies.

Signature
Mike
Nutter327 - 22 Apr 2009 18:29 GMT
Mike:
This is not the code that I used in vba... it is the concept i used in vba.
He was asking the question using dotnet language... so i tweeked it. I
understand that the post was a bit old, but sometimes we fail to get an
answer and find a less desirable solution. I thought that I would try to
help. He had posted the question on several message boards, none of which had
a workable solution in the responses.
I am relatively new to developing. If you have some advice, I am willing to
listen, but again, I was the only one to provide a solution, albeit late.
Nutter327 - 21 Apr 2009 22:16 GMT
You will have to repeat the process (add parent property) for the class
'mytooth'!