[back to
Using the object-oriented features of LotusScript
]
The BetterList class
Public Class BetterList
Private m_list List As Variant
Private m_count As Integer
Property Get Count As Integer
Count = m_count
End Property
Public Function DeleteList
Erase m_list
End Function
Public Sub new
m_count = 0
End Sub
Sub Delete
Call Me.DeleteList
End Sub
Public Function DeleteItem(key As String) As Integer
Dim rval As Integer
'if the key is in the list, erase the object
If ( Iselement(m_list(key)) ) Then
Erase m_list(key)
m_count = m_count-1
rval = True
Else
'if there's no such key, warn of an error
rval = False
Print "Item " & key & " not found. It could not be deleted."
End If
DeleteItem = rval
End Function
Public Function AddItem(key As String, item As ListItem) As Integer
'just add the item if the key doesn't exist
If ( Not Iselement(m_List(key)) ) Then
Set m_list(key) = item
m_count = m_count+1
Else
'if the key does exist, erase the current object in the list
'and add the new one
Erase m_List(key)
Set m_list(key) = item
End If
End Function
Public Function GetItem(key As String) As Variant
Dim itm As ListItem
On Error ErrListItemDoesNotExist Goto NoSuchItem
Set GetItem = m_list(key)
OK:
Exit Function
NoSuchItem:
'return a value of Nothing if the key was not found
Print "List item " & key & " not found."
Set itm= Nothing
Set GetItem = itm
Resume OK
End Function
'see if there's an object in the list for a given key
Public Function IsInList(key As String) As Integer
Dim rval As Integer
If ( Iselement(m_List(key)) ) Then
rval = True
Else
rval = False
End If
IsInList = rval
End Function
End Class