Solved

Returning a Collection from a Collection?

Posted on 2004-04-21
4
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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 …
Starting up a Project

695 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