Solved

Returning a Collection from a Collection?

Posted on 2004-04-21
4
219 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

706 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

19 Experts available now in Live!

Get 1:1 Help Now