Article ID: 178777
Article Last Modified on 10/20/2003
Option Explicit
Private m_cList As Collection
'Add
'Purpose - Add to list
'Inputs - (String) sKey
' - (Variant) vItem
Public Sub Add(ByVal sKey As String, vItem As Variant)
m_cList.Add vItem, sKey
End Sub
'Remove
'Purpose - Remove from list
'Inputs - (String) sKey
Public Sub Remove(sKey As String)
m_cList.Remove sKey
End Sub
Public Property Get Count() As Long
Count = m_cList.Count
End Property
Public Property Get Item(sKey As String) As Variant
On Error Resume Next
If m_cList.Count > 0 Then
If IsObject(m_cList(sKey)) Then
Set Item = m_cList(sKey)
Else
Item = m_cList(sKey)
End If
End If
End Property
Public Property Get NewEnum() As IUnknown
On Error Resume Next
Set NewEnum = m_cList.[_NewEnum]
End Property
Private Sub Class_Initialize()
On Error Resume Next
Set m_cList = New Collection
End Sub
Private Sub Class_Terminate()
On Error Resume Next
Set m_cList = Nothing
End Sub
<%
'Create an instance of the new collection object.
Set objMyColl = Server.CreateObject("Project1.Class1")
If IsObject(objMyColl) Then
Response.Write "Yes, I am an object" & "<BR><BR>"
'Add some test members.
objMyColl.Add CStr("1"), "Apple"
objMyColl.Add CStr("2"), "Orange"
objMyColl.Add CStr("3"), "Banana"
'Get the count of the members.
Response.Write "I have " & objMyColl.Count & " members" & "<BR><BR>"
Response.Write "The members are: " & "<BR>"
For Each Item in objMyColl
Response.Write item & "<BR>"
Next
Else
Response.Write "Server failed to create object."
End if
%>Keywords: kbprb kbarttypeinf KB178777