Class: tSortItem
Code:
Option Compare Database
Option Explicit
Public Enum tSortType
tSortAsc = 1
tSortDesc = 2
[_First] = 1
[_Last] = 2
End Enum
Private tIndex As Long
Private tField As String
Private tLastUpdated As Date
Private tTable As String
Private tSort As tSortType
' Index is read/writeable
Property Get Index() As Long
Index = tIndex
End Property
Property Let Index(Value As Long)
tIndex = Value
tLastUpdated = Now()
End Property
' Field is read/writeable
Property Get Field() As String
Field = tField
End Property
Property Let Field(Value As String)
tField = Value
End Property
' LastUpdated is read-only
Property Get LastUpdated() As Date
LastUpdated = tLastUpdated
End Property
' Sort is read/writeable
Property Get SortMethod() As tSortType
SortMethod = tSort
End Property
Property Let SortMethod(Value As tSortType)
tSort = Value
End Property
' Table is read/writeable
Property Get Table() As String
Table = tTable
End Property
Property Let Table(Value As String)
tTable = Value
End Property
Collection Class: tSortList
Code:
Option Compare Database
Option Explicit
Private tCount As Long
Private tList As Collection
Property Get Count() As Long
Count = tCount
End Property
Public Property Get Item(Index As Long) As tSortItem
Set Item = tList.Item(Index)
End Property
Public Sub Class_Initialize()
Set tList = New Collection
End Sub
Public Function NewEnum() As IUnknown
Set NewEnum = tList.[_NewEnum]
End Function
Public Sub Add(Table As String, Field As String, Optional SortMethod As tSortType = tSortAsc)
Dim tItem As tSortItem
Dim nbrSortMethod As tSortType
Set tItem = New tSortItem
If SortMethod = 0 Then
nbrSortMethod = tSortAsc
Else
nbrSortMethod = SortMethod
End If
With tItem
.Table = Table
.Field = Field
.SortMethod = nbrSortMethod
.Index = Me.Count
End With
tList.Add tItem
tCount = Me.Count + 1
End Sub
Public Sub Remove(Index As Long)
Dim i As Long
tList.Remove Index + 1 ' Because the indexing starts a one instead of zero??!?!
i = Index + 1 ' Start at the item after Index
Do While i < tList.Count + 1
tList.Item(i).Index = tList.Item(i).Index - 1
i = i + 1
Loop
tCount = Me.Count - 1
End Sub
Basically I'm trying to create a Clone() Functino for my Collection that accepts a single (Optional) Index as an argument. If the Index is provided, then a new Collection is created and ONLY that instance of my tSortItem Class is placed inside it. If no argument is passed, the entire Collection is copied.