VB Collection class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    VB Collection class

    Using VB Collection, there is a restriction that only one member can be associated with a particular key.

    E.g:

    ob.Add "user1", "key1"
    ob.Add "user2", "key1" <---------- Error - one key can have only 1 member

    Please advise of something else that can accomodate more than 1 member for the same key

    Thanks
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi
    Originally posted by questionit
    Using VB Collection, there is a restriction that only one member can be associated with a particular key.

    E.g:

    ob.Add "user1", "key1"
    ob.Add "user2", "key1" <---------- Error - one key can have only 1 member

    Please advise of something else that can accomodate more than 1 member for the same key

    Thanks
    I know (assume!) ob is an object collection, but a collection of which objects ?

    MTB

    Comment

    • questionit
      Contributor
      • Feb 2007
      • 553

      #3
      MTB

      i dont understand what you mean.
      but I've got this:

      Private ob As Collection

      Originally posted by MikeTheBike
      Hi


      I know (assume!) ob is an object collection, but a collection of which objects ?

      MTB

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by questionit
        Using VB Collection, there is a restriction that only one member can be associated with a particular key.

        E.g:

        ob.Add "user1", "key1"
        ob.Add "user2", "key1" <---------- Error - one key can have only 1 member

        Please advise of something else that can accomodate more than 1 member for the same key

        Thanks
        To the best of my knowledge, each member of a Collection must be defined by a Unique Key, so the Collection route is out. You may be able to accomplish this via a Multidimensiona l Array or a Table Structure where the combination of User and Key (Composite Key) is Unique so that multiple Users can be assigned to the same Key. You can then reference the Users assigned to a specific Key by SQL, Recordset, etc.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Originally posted by MikeTheBike
          Hi

          I know (assume!) ob is an object collection, but a collection of which objects ?

          MTB
          In Access the Collection object is not restricted to contain objects of any particular type.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32661

            #6
            Originally posted by questionit
            Using VB Collection, there is a restriction that only one member can be associated with a particular key.

            E.g:

            ob.Add "user1", "key1"
            ob.Add "user2", "key1" <---------- Error - one key can have only 1 member

            Please advise of something else that can accomodate more than 1 member for the same key

            Thanks
            More fundamentally, do you really want to store two items with the same key. The answer's almost certainly "No."
            Do you have the parameters the right way around?
            The key parameter should be a unique identifier for that particular object (instance of an object technically).

            Comment

            • questionit
              Contributor
              • Feb 2007
              • 553

              #7
              Yes in my example, i need to associate more than 1 member with one Key

              Its simply 1 to many relationship.

              I thought there would be something similar to Collection in VB that i can use. But if there isn't i would go for making an 2D array.
              Originally posted by NeoPa
              More fundamentally, do you really want to store two items with the same key. The answer's almost certainly "No."
              Do you have the parameters the right way around?
              The key parameter should be a unique identifier for that particular object (instance of an object technically).

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32661

                #8
                It doesn't make a lot of sense to store them all in the same collection then I suggest.
                What if you store the one side of the situation in one collection and the many side in another. Just as in a database, the many key could consist of the one key as well as an extra unique part to identify it uniquely.

                Comment

                Working...