Results 1 to 6 of 6

Thread: Cycling through class members

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Klamath Falls, OR
    Posts
    71

    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

  2. #2
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    I don't think there is a way to tell how many instances of an object are open. Alot of it depends on how the object has its instnacing property set. If its Multiuse you might have several instances running but only 1 object is created, whereas Singluse cretes a new object for each instance.


    There is no Instance Collection, so i really don't see how you could know how many instances are open.

    I could be wrong!
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Klamath Falls, OR
    Posts
    71
    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.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Klamath Falls, OR
    Posts
    71
    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.

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If they are in a collection then your code would look more like:
    VB Code:
    1. dim Inst as cWhatever
    2. For Each Inst in MyCollectionClass
    3.  If Inst.Property=Something Then Msgbox "Tada!"
    4. 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
  •  



Click Here to Expand Forum to Full Width