Results 1 to 3 of 3

Thread: Collections???

  1. #1

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243

    Unhappy

    Hi,
    I have a collection which I want to populate with some Contact objects. Each contact object has properties such as name,address etc. and are stored in a SQl database. I loop through the recordset and populate each contact object before adding it to my collection!
    However, when this is done, all the objects in the collection are exactly the same .
    I have stepped through in debug mode and every time it adds a new contact object to the collection, it changes all the previous objects in the collection into the new object so that when it is finished, all the objects in the collection are equal to the last one added. Why?

    Any help would be appreciated

    Shaun

    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Sydney, Australia
    Posts
    74
    It sounds to me like you havent actually used a new object each time. If you havent used the new keyword each time you have been adding a new contact object to the collection then all you have been doing is adding pointers to contact obejects toe the collection. Since all of the pointers point to the same object, the data is the same. To get around this the easiest way would probly be to crate a seperate sub which creates a NEW contact object then adds it to the collection.



  3. #3

    Thread Starter
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243

    Thumbs up

    Thanks.

    That was exactly what I was doing. Works fine now!
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

Posting Permissions

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



Click Here to Expand Forum to Full Width