Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting a class as a property

Status
Not open for further replies.

RBSTR

Programmer
Nov 10, 2005
71
0
0
GB
Hi
I am trying to set a class as a property of another class.
I have one class clsCompany and another clsPerson
I am trying to set clsPerson as a property of clsCompany and as an array.
Elsewhere in clsCompany I am setting the number of of 'clsPerson' instances (PersonCount) and creating a local array of Person instances (moPerson).
I then try and return the clsPerson as follows in my code

Code:
For intCnt = 1 To oCompany.PersonCount
  Debug.print oCompany.Person(intCnt).Surname
Next

Code:
Public Property Get Person(ByVal iI As Integer) As clsPerson
  Set Person(iI) = New clsPerson   'Problem with this line
  iI = iI - 1                                                      
  If iI >= 0 And iI <= UBound(moPerson) Then        
      Set Person(iI) = moPerson(iI)                       
  End If
    
End Property

As soon as it gets to 'Set Person(iI) = New clsPerson' it just loops through from 'Public Property Get Person...'

How can I best achieve what I am trying to do?

Many thanks in advance.
 
Try this:
___
[tt]
Public Property Get Person(ByVal iI As Integer) As clsPerson
iI = iI - 1
If iI >= 0 And iI <= UBound(moPerson) Then
Set Person = moPerson(iI)
End If
End Property[/tt]
___

The procedure will return Nothing if a wrong index is passed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top