+ Reply to Thread
Results 1 to 2 of 2

Custom Collection

  1. #1
    Registered User
    Join Date
    03-22-2005
    Posts
    2

    Question Custom Collection

    Hi guys,

    Just starting with VBA objects and I got stuck at the very beginning.

    I created "Student" class with code:

    Public FirstName As String
    Public LastName As String


    And then in the module:

    Sub TestStudent()
    Dim oStudent As New Student
    Dim Students As New Collection

    With oStudent
    .FirstName = "Bart"
    .LastName = "Simmons"
    End With
    Students.Add oStudent, "a"

    With oStudent
    .FirstName = "Lisa"
    .LastName = "Simmons"
    End With
    Students.Add oStudent, "b"

    End Sub


    as a result I expected:

    Students.Item("a").FirstName

    to have value "Bart"

    unfortunately values of all items in students collection changes each time when change oStudent object, and returns the last added value.

    Where am I wrong ?

    Gonzul
    Last edited by gonzul; 03-22-2005 at 10:02 AM.

  2. #2
    Registered User
    Join Date
    03-22-2005
    Posts
    2
    Well,
    now I know
    after each addition to collection an object has to be released with

    Set oStudent = Nothing

    and then created again

    Gonzul

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1