VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsFOTAObjectArray"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private m_oaArray() As Object
Private m_osKeys() As String
Private m_baInUse() As Boolean
Private m_nMax As Long
Private m_nUseNext As Long

'Public Function GetFirstKeyForText(sText As String) As String
'    GetFirstKeyForText = m_oaArray(m_cKEY, GetIndexForText(sText))
'End Function
Public Function GetObjectForKey(sKey As String) As Object
    Set GetObjectForKey = m_oaArray(GetIndexForKey(sKey))
End Function
Public Function KeyInList(sKey As String) As Boolean
    KeyInList = (GetIndexForKey(sKey) > -1)
End Function
Public Sub Remove(sKey As String)
    Dim nIndex As Long
    nIndex = GetIndexForKey(sKey)
    m_baInUse(nIndex) = False
    Set m_oaArray(nIndex) = Nothing
    m_osKeys(nIndex) = ""
End Sub
'Public Function GetIndexForText(sText As String) As Long
'    Dim i As Long
'    GetIndexForText = -1
'    For i = 0 To m_nUseNext - 1
'        If m_baInUse(i) = True And m_oaArray(m_cTEXT, i) = sText Then
'            GetIndexForText = i
'            Exit Function
'        End If
'    Next i
'End Function
Public Function GetIndexForKey(sKey As String) As Long
    Dim i As Long
    GetIndexForKey = -1
    For i = 0 To m_nUseNext - 1
        If m_baInUse(i) = True And m_osKeys(i) = sKey Then
            GetIndexForKey = i
            Exit Function
        End If
    Next i
End Function
Public Sub RemoveAll()
    Dim i As Long
    For i = 0 To m_nUseNext - 1
        If m_baInUse(i) = True Then
            Call Remove(m_osKeys(i))
        End If
    Next i
End Sub
Public Function Count() As Long
    Dim i As Long
    Count = 0
    'Find a free key if their is one
    For i = 0 To m_nUseNext - 1
        If m_baInUse(i) = True Then
            Count = Count + 1
        End If
    Next i
End Function
Public Sub Add(oObject As Object, sKey As String)

    Dim i As Long
    Dim nIndex As Long
    Dim bFound As Boolean
    
    'Find a free key if their is one
    For i = 0 To m_nUseNext - 1
        If m_baInUse(i) = False Then
            bFound = True
            nIndex = i
        End If
    Next i
    
    If bFound = False Then
        nIndex = m_nUseNext
        m_nUseNext = m_nUseNext + 1
        If m_nUseNext > m_nMax Then
            Call ReDimArray((m_nMax + 1) * 2)
        End If
    End If
    
    Set m_oaArray(nIndex) = oObject
    m_osKeys(nIndex) = sKey
    m_baInUse(nIndex) = True
    
End Sub
Private Sub Class_Initialize()
    m_nUseNext = 0
    m_nMax = 5
    Call ReDimArray(m_nMax)
End Sub
Private Sub ReDimArray(nMax As Long)
    ReDim Preserve m_oaArray(0 To nMax) As Object
    ReDim Preserve m_osKeys(0 To nMax) As String
    ReDim Preserve m_baInUse(0 To nMax) As Boolean
    m_nMax = nMax
End Sub

