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

Private Const m_cTEXT As Long = 1
Private Const m_cKEY As Long = 0

Private m_oaArray() As String
Private m_baInUse() As Boolean
Private m_nMax As Long
'Not Used
Private m_nUseNext As Long

Public Function Copy() As clsFOTAArray
1
2           Dim i As Long
3           Set Copy = New clsFOTAArray
4
5           For i = 0 To m_nMax
6               If m_baInUse(i) = True Then
7                   Call Copy.Add(m_oaArray(m_cTEXT, i), m_oaArray(m_cKEY, i))
8               End If
9           Next i
10
End Function

Public Function GetKeyForIndex(nIndex As Long) As String
1           Dim nFound As Long
2           Dim i As Long
3           nFound = 0
4
5           For i = 0 To m_nMax
6               If m_baInUse(i) = True Then
7                   nFound = nFound + 1
8                   If nFound = nIndex Then
9                       GetKeyForIndex = m_oaArray(m_cKEY, i)
10                      Exit Function
11                  End If
12              End If
13          Next i
14
15          Call Err.Raise(-1, "FOTATools.clsFOTAArray.GetKeyForIndex", "No key found at specified index")
16
End Function
Public Function GetTextForIndex(nIndex As Long) As String
1           Dim nFound As Long
2           Dim i As Long
3           nFound = 0
4
5           For i = 0 To m_nMax
6               If m_baInUse(i) = True Then
7                   nFound = nFound + 1
8                   If nFound = nIndex Then
9                       GetTextForIndex = m_oaArray(m_cTEXT, i)
10                      Exit Function
11                  End If
12              End If
13          Next i
14
15          Call Err.Raise(-1, "FOTATools.clsFOTAArray.GetTextForIndex", "No text found at specified index")
16
End Function

Public Property Let Text(sKey As String, sNewText As String)
1           Dim nIndex As Long
2           nIndex = GetIndexForKey(sKey)
3           If nIndex > -1 Then
4               m_oaArray(m_cTEXT, nIndex) = sNewText
5           Else
6               Call Err.Raise(-1, "FOTATools.clsFOTAArray.Text", "Key " & sKey & " not in Array")
7           End If
End Property
Public Property Get Text(sKey As String) As String
1           Dim nIndex As Long
2           nIndex = GetIndexForKey(sKey)
3           If nIndex > -1 Then
4               Text = m_oaArray(m_cTEXT, nIndex)
5           Else
6               Call Err.Raise(-1, "FOTATools.clsFOTAArray.Text", "Key " & sKey & " not in Array")
7           End If
End Property
Public Function GetFirstKeyForText(stext As String) As String
1           Dim nIndex As Long
2           nIndex = GetIndexForText(stext)
3           If nIndex = -1 Then
4               Call Err.Raise(-1, "FOTATools.clsFOTAArray.GetFirstKeyForText", "Text specified does not exist in the array")
5           Else
6               GetFirstKeyForText = m_oaArray(m_cKEY, nIndex)
7           End If
End Function
Public Function GetTextForKey(sKey As String) As String
1           Dim nIndex As Long
2           nIndex = GetIndexForKey(sKey)
3           If nIndex = -1 Then
4               Call Err.Raise(-1, "FOTATools.clsFOTAArray.GetTextForKey", "Key specified does not exist in the array")
5           Else
6               GetTextForKey = m_oaArray(m_cTEXT, nIndex)
7           End If
End Function
Public Function KeyInList(sKey As String) As Boolean
1           KeyInList = (GetIndexForKey(sKey) > -1)
End Function
Public Function TextInList(stext As String) As Boolean
1           TextInList = (GetIndexForText(stext) > -1)
End Function
Public Sub Remove(sKey As String)
1           Dim nIndex As Long
2           nIndex = GetIndexForKey(sKey)
3           m_baInUse(nIndex) = False
4           m_oaArray(m_cTEXT, nIndex) = ""
5           m_oaArray(m_cKEY, nIndex) = ""
End Sub
Public Sub RemoveIndex(nIndex As Long)
1           m_baInUse(nIndex - 1) = False
2           m_oaArray(m_cTEXT, nIndex - 1) = ""
3           m_oaArray(m_cKEY, nIndex - 1) = ""
End Sub

Public Function GetIndexForText(stext As String) As Long
1           Dim i As Long
2           GetIndexForText = -1
3           For i = 0 To m_nMax - 1
4               If m_baInUse(i) = True And m_oaArray(m_cTEXT, i) = stext Then
5                   GetIndexForText = i
6                   Exit Function
7               End If
8           Next i
End Function
Public Function GetIndexForKey(sKey As String) As Long
1           Dim i As Long
2           GetIndexForKey = -1
3           For i = 0 To m_nMax - 1
4               If m_baInUse(i) = True And m_oaArray(m_cKEY, i) = sKey Then
5                   GetIndexForKey = i
6                   Exit Function
7               End If
8           Next i
End Function
Public Sub RemoveAll()
1           Dim i As Long
2           For i = 0 To m_nMax - 1
3               If m_baInUse(i) = True Then
4                   Call Remove(m_oaArray(m_cKEY, i))
5               End If
6           Next i
End Sub
Public Function Count() As Long
1           Dim i As Long
2           Count = 0
3           'Find a free key if their is one
4           For i = 0 To m_nMax - 1
5               If m_baInUse(i) = True Then
6                   Count = Count + 1
7               End If
8           Next i
End Function
Public Sub Add(stext As String, sKey As String)
1
2           Dim i As Long
3           Dim nIndex As Long
4           Dim bFound As Boolean
5
6           'Find a free key if their is one
7           For i = 0 To m_nMax - 1
8               If m_baInUse(i) = False Then
9                   bFound = True
10                  nIndex = i
11                  Exit For
12              End If
13          Next i
14
15          If bFound = False Then
16              nIndex = m_nMax
17              Call ReDimArray((m_nMax + 1) * 2)
18          End If
19
20          m_oaArray(m_cTEXT, nIndex) = stext
21          m_oaArray(m_cKEY, nIndex) = sKey
22          m_baInUse(nIndex) = True
23
End Sub
Private Sub Class_Initialize()
1           m_nMax = 5
2           Call ReDimArray(m_nMax)
End Sub
Private Sub ReDimArray(nMax As Long)
1           ReDim Preserve m_oaArray(0 To 1, 0 To nMax) As String
2           ReDim Preserve m_baInUse(0 To nMax) As Boolean
3           m_nMax = nMax
End Sub
