By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,995 Members | 1,195 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,995 IT Pros & Developers. It's quick & easy.

Accessing a Parent Object's Properties

P: n/a
RSH
Hi,

I have a situation where I have a Parent Object (Company) which has several
public properties. The Company Object also creates an Employees object
which has its ow set of functions and properties. I am trying to figure out
how to access the Parent properties from the child object.

Simplified example:
Class Company
Public ReadOnly Property Employees() As Employees

Public Sub New(ByVal CompanyID As String)

_CompanyID = CompanyID

_Employees = New Employees(_CompanyID)

End Sub

Get

Return _Employees

End Get

End Property

Public ReadOnly Property CompanyID() As String

Get

Return _CompanyID

End Get

End Property

Public Property DateLow() As Date

Get

Return _DateLow

End Get

Set(ByVal Value As Date)

_DateLow = Value

End Set

End Property

Public Property DateHi() As Date

Get

Return _DateHi

End Get

Set(ByVal Value As Date)

_DateHi = Value

End Set

End Property

End Class

Class Employees
>>>How do I get at the CompanyID Property of the Company Parent Object??
End Class

Thanks,

Ron


Mar 5 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Add a reference to the Company in the Employees class. When you create the
Employees class, fill in reference with the parent that created it.

Robin S.
------------------------------
"RSH" <wa*************@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
Hi,

I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an Employees
object which has its ow set of functions and properties. I am trying to
figure out how to access the Parent properties from the child object.

Simplified example:
Class Company
Public ReadOnly Property Employees() As Employees

Public Sub New(ByVal CompanyID As String)

_CompanyID = CompanyID

_Employees = New Employees(_CompanyID)

End Sub

Get

Return _Employees

End Get

End Property

Public ReadOnly Property CompanyID() As String

Get

Return _CompanyID

End Get

End Property

Public Property DateLow() As Date

Get

Return _DateLow

End Get

Set(ByVal Value As Date)

_DateLow = Value

End Set

End Property

Public Property DateHi() As Date

Get

Return _DateHi

End Get

Set(ByVal Value As Date)

_DateHi = Value

End Set

End Property

End Class

Class Employees
>>>>How do I get at the CompanyID Property of the Company Parent Object??

End Class

Thanks,

Ron


Mar 6 '07 #2

P: n/a
RSH
How exactly do I do that from a childs perspective?

Thanks
Ron
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:2e******************************@comcast.com. ..
Add a reference to the Company in the Employees class. When you create the
Employees class, fill in reference with the parent that created it.

Robin S.
------------------------------
"RSH" <wa*************@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
>Hi,

I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an Employees
object which has its ow set of functions and properties. I am trying to
figure out how to access the Parent properties from the child object.

Simplified example:
Class Company
Public ReadOnly Property Employees() As Employees

Public Sub New(ByVal CompanyID As String)

_CompanyID = CompanyID

_Employees = New Employees(_CompanyID)

End Sub

Get

Return _Employees

End Get

End Property

Public ReadOnly Property CompanyID() As String

Get

Return _CompanyID

End Get

End Property

Public Property DateLow() As Date

Get

Return _DateLow

End Get

Set(ByVal Value As Date)

_DateLow = Value

End Set

End Property

Public Property DateHi() As Date

Get

Return _DateHi

End Get

Set(ByVal Value As Date)

_DateHi = Value

End Set

End Property

End Class

Class Employees
>>>>>How do I get at the CompanyID Property of the Company Parent Object??

End Class

Thanks,

Ron



Mar 6 '07 #3

P: n/a
You don't. If the child doesn't have the information, it doesn't. You
have to put the information there from the parents perspective.

You can add a reference to the company as a parameter to the constructor
of the Employees collection.

RSH wrote:
How exactly do I do that from a childs perspective?

Thanks
Ron
"RobinS" <Ro****@NoSpam.yah.nonewrote in message
news:2e******************************@comcast.com. ..
>Add a reference to the Company in the Employees class. When you create the
Employees class, fill in reference with the parent that created it.

Robin S.
------------------------------
"RSH" <wa*************@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl. ..
>>Hi,

I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an Employees
object which has its ow set of functions and properties. I am trying to
figure out how to access the Parent properties from the child object.

Simplified example:
Class Company
Public ReadOnly Property Employees() As Employees

Public Sub New(ByVal CompanyID As String)

_CompanyID = CompanyID

_Employees = New Employees(_CompanyID)

End Sub

Get

Return _Employees

End Get

End Property

Public ReadOnly Property CompanyID() As String

Get

Return _CompanyID

End Get

End Property

Public Property DateLow() As Date

Get

Return _DateLow

End Get

Set(ByVal Value As Date)

_DateLow = Value

End Set

End Property

Public Property DateHi() As Date

Get

Return _DateHi

End Get

Set(ByVal Value As Date)

_DateHi = Value

End Set

End Property

End Class

Class Employees

>>How do I get at the CompanyID Property of the Company Parent Object??
End Class

Thanks,

Ron


--
Göran Andersson
_____
http://www.guffa.com
Mar 6 '07 #4

P: n/a
RSH
Thank you. That would explain it.

Everything works now.

Ron

"RSH" <wa*************@yahoo.comwrote in message
news:%2******************@TK2MSFTNGP04.phx.gbl...
Hi,

I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an Employees
object which has its ow set of functions and properties. I am trying to
figure out how to access the Parent properties from the child object.

Simplified example:
Class Company
Public ReadOnly Property Employees() As Employees

Public Sub New(ByVal CompanyID As String)

_CompanyID = CompanyID

_Employees = New Employees(_CompanyID)

End Sub

Get

Return _Employees

End Get

End Property

Public ReadOnly Property CompanyID() As String

Get

Return _CompanyID

End Get

End Property

Public Property DateLow() As Date

Get

Return _DateLow

End Get

Set(ByVal Value As Date)

_DateLow = Value

End Set

End Property

Public Property DateHi() As Date

Get

Return _DateHi

End Get

Set(ByVal Value As Date)

_DateHi = Value

End Set

End Property

End Class

Class Employees
>>>>How do I get at the CompanyID Property of the Company Parent Object??

End Class

Thanks,

Ron


Mar 6 '07 #5

P: n/a
RSH wrote:
I have a situation where I have a Parent Object (Company) which has several
public properties. The Company Object also creates an Employees object
which has its ow set of functions and properties. I am trying to figure out
how to access the Parent properties from the child object.
Something like this:

Class Parent
Public Sub New(name As String)
m_sName = name
End Sub

Public Function GetEmployee(empNo as String) as Employee
Return New Employee(Me, empNo)
End Function

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Property

Private m_sName as String = "Bogus Co."

End Class

Class Employee
' Prevent access to default constructor
Private Sub New()
End Sub

Friend Sub New(parent as Company, empNo as String)
m_oParent = parent
m_empNo = empNo
End Sub

Public ReadOnly Property Company() as Company
Get
Return m_oParent
Get
End Property

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Sub

Private m_oParent as Company
Private m_sName as String

End Class

.... then ...

Dim c as New Company( "Bogus Co." )
Dim e as c.GetEmployee( "ABC123" )

? c.Company.Name
"Bogus Co."

HTH,
Phill W.
Mar 6 '07 #6

P: n/a

"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:es**********@south.jnrs.ja.net...
RSH wrote:
>I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an Employees
object which has its ow set of functions and properties. I am trying to
figure out how to access the Parent properties from the child object.

Something like this:

Class Parent
Public Sub New(name As String)
m_sName = name
End Sub

Public Function GetEmployee(empNo as String) as Employee
Return New Employee(Me, empNo)
End Function

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Property

Private m_sName as String = "Bogus Co."

End Class

Class Employee
' Prevent access to default constructor
Private Sub New()
End Sub

Friend Sub New(parent as Company, empNo as String)
m_oParent = parent
m_empNo = empNo
End Sub

Public ReadOnly Property Company() as Company
Get
Return m_oParent
Get
End Property

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Sub

Private m_oParent as Company
Private m_sName as String

End Class

... then ...

Dim c as New Company( "Bogus Co." )
Dim e as c.GetEmployee( "ABC123" )

? c.Company.Name
"Bogus Co."

HTH,
Phill W.
Nice job.

Robin S.
Mar 7 '07 #7

P: n/a
RobinS wrote:
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:es**********@south.jnrs.ja.net...
>RSH wrote:
>>I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an Employees
object which has its ow set of functions and properties. I am trying to
figure out how to access the Parent properties from the child object.
Something like this:

Class Parent
Public Sub New(name As String)
m_sName = name
End Sub

Public Function GetEmployee(empNo as String) as Employee
Return New Employee(Me, empNo)
End Function

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Property

Private m_sName as String = "Bogus Co."

End Class

Class Employee
' Prevent access to default constructor
Private Sub New()
End Sub

Friend Sub New(parent as Company, empNo as String)
m_oParent = parent
m_empNo = empNo
End Sub

Public ReadOnly Property Company() as Company
Get
Return m_oParent
Get
End Property

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Sub

Private m_oParent as Company
Private m_sName as String

End Class

... then ...

Dim c as New Company( "Bogus Co." )
Dim e as c.GetEmployee( "ABC123" )

? c.Company.Name
"Bogus Co."

HTH,
Phill W.

Nice job.

Robin S.
Lousy employer, though ...

Sure, their employees have Names, not numbers, but what about Salary!!
;-)

Many Thanks,
Phill W.
Mar 9 '07 #8

P: n/a

"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:es**********@south.jnrs.ja.net...
RobinS wrote:
>"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-kwrote in message
news:es**********@south.jnrs.ja.net...
>>RSH wrote:

I have a situation where I have a Parent Object (Company) which has
several public properties. The Company Object also creates an
Employees object which has its ow set of functions and properties. I
am trying to figure out how to access the Parent properties from the
child object.
Something like this:

Class Parent
Public Sub New(name As String)
m_sName = name
End Sub

Public Function GetEmployee(empNo as String) as Employee
Return New Employee(Me, empNo)
End Function

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Property

Private m_sName as String = "Bogus Co."

End Class

Class Employee
' Prevent access to default constructor
Private Sub New()
End Sub

Friend Sub New(parent as Company, empNo as String)
m_oParent = parent
m_empNo = empNo
End Sub

Public ReadOnly Property Company() as Company
Get
Return m_oParent
Get
End Property

Public ReadOnly Property Name() as String
Get
Return m_sName
End Get
End Sub

Private m_oParent as Company
Private m_sName as String

End Class

... then ...

Dim c as New Company( "Bogus Co." )
Dim e as c.GetEmployee( "ABC123" )

? c.Company.Name
"Bogus Co."

HTH,
Phill W.

Nice job.

Robin S.

Lousy employer, though ...

Sure, their employees have Names, not numbers, but what about Salary!!
;-)

Many Thanks,
Phill W.
LOL.

Robin S.
Mar 9 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.