Option Explicit
Private mCol As Collection Public Function Exists(Key) As Boolean Dim v As Variant On Local Error GoTo NoItem If IsObject(mCol(Key)) Then Set v = mCol(Key) Set v = Nothing Else v = mCol(Key) End If Exists = True Exit Function NoItem: Exists = False Exit Function End Function Public Sub Clear() Set mCol = New Collection End Sub Public Sub Add(Item, Optional Key, Optional Before, Optional After) If IsMissing(Key) Then mCol.Add Item Else If IsMissing(Before) Then mCol.Add Item, Key Else If IsMissing(After) Then mCol.Add Item, Key, Before Else mCol.Add Item, Key, Before, After End If End If End If End Sub Public Property Get Item(vntIndexKey As Variant) As Variant If IsObject(mCol(vntIndexKey)) Then Set Item = mCol(vntIndexKey) Else Item = mCol(vntIndexKey) End If End Property Public Property Get Count() As Long Count = mCol.Count End Property Public Sub Remove(vntIndexKey As Variant) mCol.Remove vntIndexKey End Sub Public Property Get NewEnum() As IUnknown Set NewEnum = mCol.[_NewEnum] End Property Private Sub Class_Initialize() 'creates the collection when this class is created Set mCol = New Collection End Sub Private Sub Class_Terminate() 'destroys collection when this class is terminated Set mCol = Nothing End Sub |