Private Const CAPACITY_INCREMENT = 512
Private Const ARRAY_BASE = -32768
'############################################################################
####
Public Class VariantList
Private values() As Variant
Private count As Long
Private capacity As Long
Private Sub init()
capacity = CAPACITY_INCREMENT
count = 0
Redim values(0 + ARRAY_BASE To capacity - 1 + ARRAY_BASE)
End Sub
Private Sub EnsureCapacity(minCapacity As Long)
Dim newCapacity As Long
newCapacity = capacity
While (newCapacity < minCapacity)
newCapacity = newCapacity + CAPACITY_INCREMENT
Wend
If (capacity < newCapacity) Then
capacity = newCapacity
Redim Preserve values(0 + ARRAY_BASE To capacity - 1 + ARRAY_BASE)
End If
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~
Public Sub New
Call init()
End Sub
Public Sub Delete
Erase values
End Sub
Public Sub add(value As Variant)
ensureCapacity(count + 1)
If Isobject(value) Then
Set values(count + ARRAY_BASE) = value
Else
values(count + ARRAY_BASE) = value
End If
count = count + 1
End Sub
Public Sub clear()
Erase values
Call init()
End Sub
Public Function getElement(index As Long) As Variant
If (index >= count) Then Exit Function
If Isobject(values(index + ARRAY_BASE)) Then
Set getElement = values(index + ARRAY_BASE)
Else
getElement = values(index + ARRAY_BASE)
End If
End Function
Public Function size() As Long
size = count
End Function
End Class
'############################################################################
####