Can anyone explain me why do I get thousands of identical items even if I change the item that I'm loading??
Printable View
Can anyone explain me why do I get thousands of identical items even if I change the item that I'm loading??
Can you expand on that a little?
:confused:
Quote:
Originally posted by crptcblade
Can you expand on that a little?
:confused:
VB Code:
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.
:confused:
That's weird.
u sure ur pFields isn't always pointing to the same thin' or ur
rs(IDIndex) hadn't any problemo?
No... try it and you'll see.
Can you post it?
I think I might know the issue.Quote:
Originally posted by Mc Brain
Can you post it?
Here is the code that behaves correctly
VB Code:
Private Sub Command1_Click() Dim c As New Collection Dim cls As Class1 Dim x As Integer For x = 1 To 10 Set cls = New Class1 cls.i = x cls.s = "Test" & x c.Add cls, x & x Next For Each cls In c Debug.Print cls.i, cls.s Next Set c = Nothing End Sub
Here is the code that doesn't work correctly
VB Code:
Private Sub Command1_Click() Dim c As New Collection Dim cls As Class1 Dim x As Integer Set cls = New Class1 For x = 1 To 10 cls.i = x cls.s = "Test" & x c.Add cls, x & x Next For Each cls In c Debug.Print cls.i, cls.s Next Set c = Nothing End Sub
Does yours look similar to the second?
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??
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.
Any work aorund?
Why is it that you can't do it the first way?
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)
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.
I had the "first way" before.... but I need to change it because it's too slow.
crptcblade, thank you very much. Had the same problem today:)