Solved

Returning a Collection from a Collection?

Posted on 2004-04-21
4
223 Views
Last Modified: 2012-05-04
Giving the following short collection as an example:

Private mcolMacro As Collection

Public Sub Add(Item As ColMacro, Key As String)

On Error GoTo Eh:
    mcolMacro.Add Item, Key

On Error GoTo 0
Exit Sub

Eh:
    'dupes will not be assimilated into the collection
    'Debug.Print Err.Number & "  " & Err.Description & " Key Exists: " & Key
    Resume Next
    On Error GoTo 0

End Sub

Public Property Get Count() As Integer
    Count = mcolMacro.Count
End Property

Public Function ItemByIndex(Index As Integer) As ColMacro
    Set ItemByIndex = mcolMacro.Item(Index)
End Function

Public Function ItemByKey(Key As String) As ColMacro
    Set ItemByKey = mcolMacro.Item(Key)
End Function

Private Sub Class_Initialize()
    Set mcolMacro = New Collection
End Sub

Where ColMacro is essentially a UDT, how can I approach writing a member of ColMacros that would take in criteria and return a collection of all the ColMacros that meets this criteria?
0
Comment
Question by:falkor
4 Comments
 
LVL 19

Expert Comment

by:Melih SARICA
ID: 10881681
mconMacro.add(new Collection) ?
0
 
LVL 1

Author Comment

by:falkor
ID: 10881799
Not too sure what that means.  Let's say I have a collection of colMacros call CurrentList.  I want to be able to write a method of colMacros that would access all the members of CurrentList, returning all the members into a new collection that met specific criteria

Something like this?
Set NewList = New ColMacros
Set NewList = CurrentList.GetMatches("condition on members")

Or something like that.  I may not be explaining myself clearly.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 10882222
>> Where ColMacro is essentially a UDT

Can you show us the format of the items being put into ColMacro and an example of a search you might want to execute?

Idle_Mind
0
 
LVL 8

Accepted Solution

by:
rajaloysious earned 500 total points
ID: 10887529
****Where ColMacro is essentially a UDT*****
Means the following i guess
Type ColMacro
    P as integer
    Q as String
    L as double
End Type
*********
how can I approach writing a member of ColMacros that would take in criteria and return a collection of all the ColMacros that meets this criteria?
***********
Then just this method solves  the above that would take in criteria and return a collection of all the ColMacros
Public Function Items(Criteria As String/Integer) As Collection
    Dim oReturnCollection as Collection
    For nIndex = 1 to mcolMacro.Count
        If mcolMacro(nIndex).P= 1 Then        ''Meets Ctritera =====Here the criteria is that the P member of the type colMacro shd be 1
               oReturnCollection .Add  mcolMacro(nIndex), mcolMacro(nIndex).Key
        end if
    Next
End Function


This solves the problem. Good Luck
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 93
Plain Text Editor for iPad 6 75
simplest php form 3 77
How to Convert a Quote to an Order in SalesForce 2 36
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now