Public Class GrowingArray
'declarations
Private pSize As Integer
Private pCapacity As Integer
Private pValues() As String
Private pUnique As Boolean
Public Sub New(unique As Boolean)
'initialize
Me.pUnique = unique
Me.pSize = -1
Me.pCapacity = 10
Redim Me.pValues(Me.pCapacity)
End Sub
Public Sub Init(doc As NotesDocument, itemname As String)
If Not doc.HasItem(itemname) Then
'simply return
Exit Sub
End If
Dim v As Variant
Dim i As Integer
v = doc.GetItemValue(itemname)
For i=0 To Ubound(v)
Call Me.Add(v(i))
Next
End Sub
Public Property Get Size As Integer
Size = Me.pSize + 1
End Property
Public Property Get Empty As Boolean
If Size = 0 Then
Empty = True
Else
Empty = False
End If
End Property
Public Property Get Values As Variant
'declarations
Dim v() As String
'handle empty
If Me.pSize <= -1 Then
Values = v
Exit Property
End If
'if the size is less than the capacity reduce
If Me.pSize <> Me.pCapacity Then
'create reduced array
Redim v(Me.pSize)
Dim i As Integer
For i=0 To Me.pSize
v(i) = Me.pValues(i)
Next
Values = v
Exit Property
End If
'just return
Values = Me.pValues
End Property
Public Sub Add(v As String)
If v = "" Then
Exit Sub
End If
If Me.pUnique Then
'see if unique
Dim i As Integer
For i=0 To Me.pSize
If Me.pValues(i) = v Then
'not unique
Exit Sub
End If
Next
End If
If Me.pSize = Me.pCapacity Then
Me.pCapacity = Me.pCapacity + 10
Redim Preserve Me.pValues(Me.pCapacity)
End If
'add
Me.pSize = Me.pSize + 1
Me.pValues(Me.pSize) = v
End Sub
End Class
Like this:
Like Loading...