Hi,
I'd really appreciate if someone could help me with this.
I have a simple program with 1 class - CPerson which has 3 properies:
-Name
-Phone
-Age

Thanks for taking the time


This is the way program should work:
1.Open PHONES.TXT and read in all records (in a loop) into variables. The file has 5 records in this format:
"John","888-6345",21 (name, phone, age). Each time a record is read-in, add object to collection (People.Add Person)
2.Assing variables to properties of object Person(Name,Phone,Age)
3.Add current object to collection
4.Ask user for a name to search
5.In a For-Next loop go through the entire collection and search for user's specified name

The problem is that when I read back contents of the collection, only last object is in it.
Please help, I don't know what's wrong.


'FORM CODE
'-------------------------------------------------
Code:
Option Explicit

Private Person As CPerson
Dim People As New Collection


Private Sub cmdRequestPerson_Click()
    Set Person = New CPerson
    
    Dim strPersonName As String
    Dim ctr As Integer
    Dim intFileNumber As Integer
    
    ' Temp variables for reading file
    Dim sName As String
    Dim sPhone As String
    Dim iAge As Integer
    
    ' Read Persons.txt in to a collection
    intFileNumber = FreeFile
    
    ' Read name, phone, age for all poeple in the file
    Open "Phones.txt" For Input As intFileNumber
    Do While (Not (EOF(intFileNumber)))
        Input #intFileNumber, sName, sPhone, iAge
        
        ' Fill object w. latest record
        Person.Name = sName
        Person.Phone = sPhone
        Person.Age = iAge
        
        ' Add current object to collection
        People.Add Person
        
    Loop
    Close #intFileNumber
    
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
txtAllPeople = People.Item(3).Name

'AT THIS POINT THERE SHOULD BE 3rd RECORD FROM THE FILE
'IN THE txtAllPeople TextBox, BUT THE ENTIRE COLLECTION
'HOLDS FIFTH RECORD
'The collection doesn't hold assinged data
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ' Get Person's name from user
    strPersonName = InputBox("Enter Person's name")
    
    ' Go thourgh the collection & find requested name
    For ctr = 1 To People.Count
        If strPersonName = People.Item(ctr).Name Then
            txtPersonInfo = People.Item(ctr).Name & _
                            People.Item(ctr).Age
            Exit Sub
        End If
    Next ctr
    
    ' Destroy object
    Set Person = Nothing
End Sub



'CLASS CODE
'-------------------------------------------------

Option Explicit

Private m_Name As String
Private m_Phone As String
Private m_Age As Integer


Property Let Name(vName As String)
    m_Name = vName
End Property

Property Get Name() As String
    Name = m_Name
End Property


Property Let Phone(vPh As String)
    m_Phone = vPh
End Property

Property Get Phone() As String
    Phone = m_Phone
End Property


Property Let Age(vAge As Integer)
    m_Age = vAge
End Property

Property Get Age() As Integer
    Age = m_Age
End Property