Click to See Complete Forum and Search --> : sub properties
noble
Feb 7th, 2001, 11:43 AM
I've done this before but i can't remember how to do it....
How do you create sub properties of a property in a class?
If i have a Class titled "Person", and a property titled "Hand", how do i create a sub property of "Hand" called "Left" and/or "Right"?
Thanks for any help.
tumblingdown
Feb 7th, 2001, 10:49 PM
Make the hand property a class itself, and give it an enum property for left and right. Something like...
'/
'/ CHand:
'/
Private m_h as enumHandedness
'/
Public Enum enumHandedness
Righty =0
Lefty
End enum
'/
Public Property Get Handedness() as enumHandedness
Handedness= m_h
End Property
Public Property Let Handedness(byval RHS as enumHandedness)
if RHS < enumHandedness.Righty or RHS > enumHandedness.Lefty Then RHS = enumHandedness.Righty '/ remember enum's are not enforced, so have a default ;-)
m_h = RHS
End Property
'/
'/ CPerson
'/
Private m_H
'/
Public Property Get Hand() as CHand
If m_H Is Nothing Then Set m_H = New CHand
Set Hand = m_H
End Property
Then whenever you use it you get...
Dim oPerson as CPerson
Set oPerson = New CPerson
oPerson.Hand.Handedness = Righty
I know that hand.handedness doesn't make logical sense, but you get the idea.
td.
noble
Feb 8th, 2001, 06:10 AM
ty, now i remember :P
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.