Results 1 to 3 of 3

Thread: collections!

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    15
    I must be really thick, but how do i retrive objects froma collection!

    i use the following code 2 add 2 a collection

    colUsers.Add myNewUserClass, myNewUserClass.UserName

    and then the follwoing 2 retirve

    Dim myItem As clsUser

    For Each myItem In colUsers
    MsgBox myItem.UserName
    Next

    but the above code retrives the repeats the name of the last class i entered. WHere am i going wrong? plz help!

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    this is proboably a byref error, are you passing classes around your code, using set cls1 = cls2 etc.

    if you do this you are not making a new copy of the class, both variable names are now pointing to the same object, so when you change the properties of one the properties of the others change.

    so what's probably happenning is you are trying to copt the class to however many places you do and adding them to the collection, so everything in the collection is in vact the same object.

    in order to copy cls1 to cls2 you have to do something like this
    Code:
    Set cls1 = New Myclass
    
    cls1.Text = cls2.Text.Property1   'you have to do this for all your properties
    it's a bit tedious but you have to do it.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    15
    Thanxs Sam!

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