|
-
Apr 24th, 2002, 02:43 PM
#1
Thread Starter
Lively Member
Cycling through class members
This is probably a dumb question, but oh well, thats what this forum is all about I guess. I need to cycle through all of the instances of a class I created and I'm not able to do it. Any help would be appriciated. I tried some code similar to this:
For Each Instance in cPlayer
Instance.Property
Next
...but It didn't work.
Thanks
-
Apr 24th, 2002, 02:58 PM
#2
-
Apr 24th, 2002, 03:51 PM
#3
Thread Starter
Lively Member
well..i guess i could just do it manually.. and check through all of my
Public NewInstance as cClassType
Set NewInstance = New cClassType
Statements and write seperate code for each one. That'd be a pain in the ass though. Sooo if anyone knows how I could do this easier. Or if there was a way to contain all the objects a different way, please let me know. If I have to re-arch my program, it won't be too big of a deal. I'm not too far into it.
-
Apr 24th, 2002, 05:10 PM
#4
You can put all your classes in a collection or even better make a collection class for your class. Then you can use For Each and loop through them.
Or do you mean from within the class and/or dll? In that case you'd have to fill a collection in a module and give them some form of ID property to make it eaiser to identify them.
-
Apr 24th, 2002, 05:40 PM
#5
Thread Starter
Lively Member
Got any ideas on how to lay that out? I've got about 30 instances of the class... and the class has about 10 different properties.. and i'm needing to search through the class and see if certian properties hold certain values.. and its gonna be a pain in the ass to say:
if instance1.property = somthing then
somthing
end if
if instance2.property = somthing then
somthing
end if
if instance3.property = somthing then
somthing
end if
And then if i want to check a different property.. then im screwed too... i've got to do it all again for a different property.. sure its just a matter of cutting and pasting.. but its real ugly.
-
Apr 24th, 2002, 05:54 PM
#6
If they are in a collection then your code would look more like:
VB Code:
dim Inst as cWhatever
For Each Inst in MyCollectionClass
If Inst.Property=Something Then Msgbox "Tada!"
Next
To make the collection classit's easiest to just use the ClassBuilder Wizard and add whatever extras you want afterwards. Then whenever you create a new instance of the class just add it too the collection.
Last edited by Edneeis; Apr 24th, 2002 at 05:57 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|