Solved

Returning a Collection from a Collection?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 63
array11 challenge 16 59
detecting  the added row index in a datagridview 3 54
Arduino EDI - Programming Language - Voice Recorder 4 65
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…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 …
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 …

932 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

11 Experts available now in Live!

Get 1:1 Help Now