DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: Collection Classes, Enabling a For Each iteration

  1. #1
    Tom Pepon Guest

    Collection Classes, Enabling a For Each iteration


    I have a class with a collection, with an Item(Index) property returning the
    Item(index) property of the member collection. I added a NewEnum function,
    as noted in the MSDN library under Creating Your Own Collection Class: The
    House of Bricks. I set the Item ProcedureID to default, and the NewEnum
    ProcedureID to -4. I can then iterate the collection class with a For Each
    loop.

    However, in adding a second collection class to my project, I cannot set
    the ProcedureID of the new class's NewEnum function to -4, since that is
    already used by the NewEnum function of the first collection class. If I
    do try and set it to -4, the first class's NewEnum ProcedureID is set to
    (default) and the Item ProcedureID to (none).

    Is there any way to enable For Each iteration in two seperate collection
    classes in the same project?

  2. #2
    Kevin Guest

    Re: Collection Classes, Enabling a For Each iteration


    I have done what you want to do in a number of projects, but I don't know
    what is wrong in your case.

    I have projects that have multiple collection classes. Each holds a collection
    of other classes. Each collection class has the Item method and Enumerate
    method setup as you defined and it works fine.

    You can do it, you just have to figure out what is different with your project
    or how you are doing it or ?

    Kevin

    "Tom Pepon" <thomaspepon@hotmail.com> wrote:
    >
    >I have a class with a collection, with an Item(Index) property returning

    the
    >Item(index) property of the member collection. I added a NewEnum function,
    >as noted in the MSDN library under Creating Your Own Collection Class: The
    >House of Bricks. I set the Item ProcedureID to default, and the NewEnum
    >ProcedureID to -4. I can then iterate the collection class with a For Each
    >loop.
    >
    >However, in adding a second collection class to my project, I cannot set
    >the ProcedureID of the new class's NewEnum function to -4, since that is
    >already used by the NewEnum function of the first collection class. If

    I
    >do try and set it to -4, the first class's NewEnum ProcedureID is set to
    >(default) and the Item ProcedureID to (none).
    >
    >Is there any way to enable For Each iteration in two seperate collection
    >classes in the same project?



  3. #3
    Thomas Pepon Guest

    Re: Collection Classes, Enabling a For Each iteration


    "Peter Young" <youngpa@mediaone.net.nospam> wrote:
    >Tom,
    >
    >> However, in adding a second collection class to my project, I cannot set
    >> the ProcedureID of the new class's NewEnum function to -4, since that

    is
    >> already used by the NewEnum function of the first collection class. If

    I
    >> do try and set it to -4, the first class's NewEnum ProcedureID is set

    to
    >> (default) and the Item ProcedureID to (none).
    >>
    >> Is there any way to enable For Each iteration in two seperate collection
    >> classes in the same project?

    >
    >You can do this. VB has a bug with the procedure attributes. It changes

    them
    >on you for no apparent reason. (I don't know if it's documented, but I've
    >sure seen it happen plenty.) Open your .cls files with a text editor and

    set
    >the attributes manually and you should be fine.
    >
    >e.g.
    >
    >Public Property Get NewEnum() As IUnknown
    >Attribute NewEnum.VB_UserMemId = -4
    >Attribute NewEnum.VB_MemberFlags = "40"
    > ...
    >
    >


    Many thanks. I'm not sure why the IDE was messing with my settings, but
    setting it in the class file seems to do the trick. Thanks again.
    --Tom


  4. #4
    Peter Young Guest

    Re: Collection Classes, Enabling a For Each iteration

    Tom,

    > However, in adding a second collection class to my project, I cannot set
    > the ProcedureID of the new class's NewEnum function to -4, since that is
    > already used by the NewEnum function of the first collection class. If I
    > do try and set it to -4, the first class's NewEnum ProcedureID is set to
    > (default) and the Item ProcedureID to (none).
    >
    > Is there any way to enable For Each iteration in two seperate collection
    > classes in the same project?


    You can do this. VB has a bug with the procedure attributes. It changes them
    on you for no apparent reason. (I don't know if it's documented, but I've
    sure seen it happen plenty.) Open your .cls files with a text editor and set
    the attributes manually and you should be fine.

    e.g.

    Public Property Get NewEnum() As IUnknown
    Attribute NewEnum.VB_UserMemId = -4
    Attribute NewEnum.VB_MemberFlags = "40"
    ...



  5. #5
    Matthew Solnit Guest

    Re: Collection Classes, Enabling a For Each iteration

    "Peter Young" <youngpa@mediaone.net.nospam> wrote in message
    news:3c10d13d$1@147.208.176.211...
    > You can do this. VB has a bug with the procedure attributes. It changes

    them
    > on you for no apparent reason. (I don't know if it's documented, but I've
    > sure seen it happen plenty.) Open your .cls files with a text editor and

    set
    > the attributes manually and you should be fine.


    I've had the same problem, and I find the best solution is SourceSafe. Only
    the .CLS file that I am currently working on is writeable, so VB can't mess
    up the others.

    -- Matthew Solnit



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center