Solved

Returning a Collection from a Collection?

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Apps blocked by Java 9 98
collection output issue 9 68
learn programming 8 73
troubleshoot a python script 8 78
In this post we will learn different types of Android Layout and some basics of an Android App.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

730 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