Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to access property of PARENT custom class instance from a CHIL

830 views
Skip to first unread message

FlashMerlot AT

unread,
Feb 23, 2009, 12:29:01 PM2/23/09
to
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
'-------------------------------------------------------------

--
F.V.

Ralph

unread,
Feb 23, 2009, 5:56:01 PM2/23/09
to

"FlashMerlot" <FlashSand (AT) gmail COM> wrote in message
news:B765CC63-3F0B-4719...@microsoft.com...

> 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

unread,
Apr 21, 2009, 5:13:01 PM4/21/09
to
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!

Nutter327

unread,
Apr 21, 2009, 5:16:01 PM4/21/09
to

You will have to repeat the process (add parent property) for the class
'mytooth'!

MikeD

unread,
Apr 21, 2009, 6:55:13 PM4/21/09
to

"Nutter327" <Nutt...@discussions.microsoft.com> wrote in message
news:5074B1C6-89D1-4BA1...@microsoft.com...

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.

--
Mike

Nutter327

unread,
Apr 22, 2009, 1:29:01 PM4/22/09
to
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.

dferg...@gmail.com

unread,
May 8, 2016, 1:29:56 AM5/8/16
to
Nutter327, your solution just helped me tremendously. I'd been trying to work out syntax that would deliver this functionality for weeks. I'd developed really kludgy workarounds but your simple concept solved it for me instantaneously. Even though your post is seven years old, it's still helping people.

MikeD, I don't often do this but I need to call you out. Your response to Nutter327 did not add anything to the discussion. It did not solve anyone's code problem but may dissuade Nutter327 from contributing his or her valuable comments in the future.
0 new messages