Results 1 to 15 of 15

Thread: Damn Collections

  1. #1

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Damn Collections

    Can anyone explain me why do I get thousands of identical items even if I change the item that I'm loading??
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Can you expand on that a little?

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by crptcblade
    Can you expand on that a little?

    VB Code:
    1. pRS.Add pFields, CStr(rs(IDIndex))

    pRS is a collection, and pFields is a class. No matter that I change the values of this class. And add them. I get all the previous records change with the last one I've loaded.

    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  4. #4
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    That's weird.
    u sure ur pFields isn't always pointing to the same thin' or ur
    rs(IDIndex) hadn't any problemo?
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  5. #5

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    No... try it and you'll see.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Can you post it?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  7. #7
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Originally posted by Mc Brain
    Can you post it?
    I think I might know the issue.

    Here is the code that behaves correctly
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim c As New Collection
    3. Dim cls As Class1
    4. Dim x As Integer
    5.  
    6.    
    7.     For x = 1 To 10
    8.         Set cls = New Class1
    9.             cls.i = x
    10.             cls.s = "Test" & x
    11.         c.Add cls, x & x
    12.     Next
    13.    
    14.     For Each cls In c
    15.         Debug.Print cls.i, cls.s
    16.     Next
    17.    
    18.     Set c = Nothing
    19.  
    20. End Sub

    Here is the code that doesn't work correctly
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim c As New Collection
    3. Dim cls As Class1
    4. Dim x As Integer
    5.  
    6.     Set cls = New Class1
    7.    
    8.     For x = 1 To 10
    9.             cls.i = x
    10.             cls.s = "Test" & x
    11.         c.Add cls, x & x
    12.     Next
    13.    
    14.     For Each cls In c
    15.         Debug.Print cls.i, cls.s
    16.     Next
    17.    
    18.     Set c = Nothing
    19.  
    20. End Sub

    Does yours look similar to the second?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  8. #8

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    It looks like the second one. And I know that the first one works... but I need to get it working with the second one.

    Why does it do this??
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Because you are not adding actual objects to the collection, just the reference to it. Since you are not setting a new reference, it will continuously update the original object.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  10. #10

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Any work aorund?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Why is it that you can't do it the first way?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  12. #12

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Because it's not as easy as your example. Each item has 76 different values. What's more... this 76 values are a collection which is generated on run-time. So, for each item (that I want to add to the main collection) I'd need to create this "object". If there are a few, there's no problem. But, when the number is huge.... the computer goes dead!!! (I mean the resources)
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  13. #13
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Okay, so you add the first, then change a value or two, then try to add it as a second, and so forth?

    Hmmm...I really don't know of any other way around. Sorry.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  14. #14

    Thread Starter
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    I had the "first way" before.... but I need to change it because it's too slow.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  15. #15
    Junior Member
    Join Date
    Dec 2006
    Posts
    21

    Re: Damn Collections

    crptcblade, thank you very much. Had the same problem today

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