AddMethod




Public Sub Add(obj As MyClass, Optional Key As String, _
Optional Before As Variant, Optional After As Variant)
Dim blnKey As Boolean
Dim blnBefore As Boolean
Dim blnAfter As Boolean
blnKey = Len(Trim(Key)) <> 0
blnBefore = Not IsMissing(Before)
blnAfter = Not IsMissing(After)
If blnBefore And blnAfter Then
Err.Raise 5
ElseIf blnKey And blnBefore Then
m_col.Add obj, Key, Before
ElseIf blnKey And blnAfter Then
m_col.Add obj, Key, , After
ElseIf blnKey Then
m_col.Add obj, Key
ElseIf blnBefore Then
m_col.Add obj, , Before
ElseIf blnAfter Then
m_col.Add obj, , , After
Else
m_col.Add obj
End If
End Sub

'***************************************************************

'Assume this collection will be created in Class_Initialize

Private m_col As Collection
'***************************************************************

' Name: Add method for Collection subclass

' Description:Include the [Key], [Before], and [After] functional

' ity of the instrinsic VB Collection class in your own subclassed

' collections.

' By: Chet Lyle

'

'

' Inputs :

' obj : The object to be added to the collection

' Key : The of the object to be added (Optional)

' Before : The index of the object in the collection before which the object to

' be added should be placed (Optional)

' After : The index of the object in the collection after which the object to

' be added should be placed (Optional)

'

' Assumes: Change the type declaration of the first input parameter

' ("MyClass") to the name of the class you are creating a collection for.

' Effects: As with the intrinsic VB Collection class' Add method,

' [Before] or [After] may be specified, but not both. Specifying both

' raises runtime error 5.

'











( addmethod.html )- by Paolo Puglisi - Modifica del 17/12/2023