Results 1 to 4 of 4

Thread: merge two collections

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Posts
    27
    Hi All,

    Does anyone know an easy way to merge two collections in vb.
    i tried the following code

    Private Sub cmdMerge_Click()

    Private col1 As New Collection
    Private col2 As New Collection
    Private col3 As New Collection

    col1.Add "1", "1"
    col2.Add "2", "2"

    col3 = col1 + col2
    End Sub

    and it flopped!
    Any suggestions pl? Thanx in advance

    okdk

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    try this,

    Code:
    Public Function MergeCollections(Coll1 As Collection, Coll2 As Collection) As Collection
    
    Dim retval As New Collection
    Dim varTemp As Variant
    
    For Each varTemp In Coll1
    
        retval.Add varTemp
        
    Next varTemp
    
    For Each varTemp In Coll2
    
        retval.Add varTemp
        
    Next varTemp
    
    Set MergeCollections = retval
    End Function
    it won't do the keys though, I'm not sure if that's possible, I can't seem to find a way of getting at the keys.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Posts
    27
    Hmm...I actually want to avoid the for loops and any other loops...that will be the final resort.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2000
    Posts
    27

    thanks but solved my problem

    hi! all

    anyways thanx for the thinking...but i got a solution to my problem...unfortunately since the details are a lil project specific...i am unable to share the solution with all of u...
    thanx anyways
    okdk

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