Trouble with Collection of Classes 
Author Message
 Trouble with Collection of Classes

Hi,
 I am using a collection of keywords in my project.  the code for the
keyword class is very simple here it is.

=========================================================================
Private mstrKeyword As String

Public Property Get Keyword() As String
    Keyword = mstrKeyword
End Property

Public Property Let Keyword(ByRef strNewValue As String)
    mstrKeyword = strNewValue
End Property
===========================================================================
Here is the code for the collection class.

Option Explicit
Private KeyCollection As Collection
Private Sub Class_Initialize()
    Set KeyCollection = New Collection
End Sub

Public Sub Add(Keyword As String, Optional skey As String)
    Dim tmpKeyword As Keyword
    Set tmpKeyword = New Keyword

    tmpKeyword.Keyword = Keyword

    If Len(skey) = 0 Then
        KeyCollection.Add tmpKeyword
    Else
        KeyCollection.Add tmpKeyword, skey
    End If

    Set tmpKeyword = Nothing

End Sub

Public Property Get Item(vintItem As Variant) As Keyword
    Set Item = KeyCollection(vintItem)

End Property

Public Property Get count() As Long
    count = KeyCollection.count

End Property

Public Sub remove(vntIndexKey As Variant)
    KeyCollection.remove vntIndexKey

End Sub

Public Property Get NewEnum() As IUnknown
    Set NewEnum = KeyCollection.[_NewEnum]

End Property

Private Sub Class_Terminate()
  'destroys collection when this class is terminated
    Set KeyCollection = Nothing
End Sub

========================================================
I have the property get newenum procedure attribute set to -4 and hidden.

Now when I get a reference to this collection, I can count how many keywords
there is.  But when I try the following code:
        Set mykeywords = mymodel.Keywords
        If mykeywords.count > 0 Then
        For Each mykeyword In mykeywords <------ Problem is here.
            count = count + 1
            fgFilters.AddItem mykeyword.Keyword
        Next
        End If
        Set mykeyword = Nothing
        Set mykeywords = Nothing

I get the error: Runtime error '449' - Argument is not optional.  There
should be no argument for this.
In the declarations I set the variables up to handle the mykeywords,
mykeyword, and mymodel types.  Can anyone point me in the right direction?

I appreciate any help.

Sincerely,

John P. Sheppard



Mon, 23 Apr 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Collection of Collections of Classes

2. VB4 class collections with collections

3. Exposing Properties collection in custom classes as many MS Classes do

4. StatusBarPanel Collection containing panels based on different classes derived from StatusBarPanel class

5. Exposing a Properties collection in custom classes as many MS Classes do

6. Raising events from a class within a collection class

7. Class as collection of another class

8. Looking for 3rd Party Class Library (Collection Class) for Visual Basic

9. Looking for 3rd Party Class Library (Collection Class) for Visual Basic

10. Trouble with items collection. (Newbie)

11. Trouble with ADO Connection.Open() Error 3625 Item not found in collection

12. Having trouble with simple COLLECTION

 

 
Powered by phpBB® Forum Software