Archived

This topic is now archived and is closed to further replies.

Daishim

VB Array problem.

Recommended Posts

I''m working on a game editor/file creation program in VB and I''ve run accross an array problem. It''s been awhile since I''ve worked this extensively with arrays and VB, I hope someone can help me out. I have an array: Public ObjectSet() as new clsSet clsSet is a class module. It is dynamically resized everytime the user creates a new set by using ReDim Preserve. Now, for argument lets say I have 5 elements. I want to remove element 4 (Index 3). For i = ''index to remove'' to (UBound(ObjectSet) - 1) ObjectSet(i) = ObjectSet(i + 1) Next i ReDim Preserve ObjectSet(UBound(ObjectSet) - 1) The line: ObjectSet(i) = ObjectSet(i + 1) generates the following error. "Object doesn''t support this property or method." I can''t remember whether the elements are being stored as references or what and my old VB books don''t really help with things like this and I can''t find anything really specific in the MSDN. The class modules are quite complex and trying to manually resize arrays within the class modules to copy data over. Anyone have any suggestions or some info to just nudge me in the right direction? Thanks.

I know only that which I know, but I do not know what I know.

Share this post


Link to post
Share on other sites
Since clsSet is a class, you need to use set to reference instances of it:

set ObjectSet(i) = ObjectSet(i + 1)

Since you need to delete random elements in the array and the size of the array is dynamic, I strongly recommend writing a Collection class to store the objects instead.


[edited by - DaTroof on January 18, 2004 1:01:23 AM]

Share this post


Link to post
Share on other sites
That did it. I''ll have to check into the Collection. Someone else just mentioned that to me, I''ve never heard of it before, but if it''s better than trying to manage arrays then I''ll have to give it a try.



I know only that which I know, but I do not know what I know.

Share this post


Link to post
Share on other sites