VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Sort"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'Klasa sort
Implements Command
Implements ParseObject
Private kids() As Kid
Private pindex As Integer
Private value As Integer
Private dta As data
Private typ As Integer
Private ptable As ListBox
Private args As New Collection
    
Public Sub init(ByVal s As String, kd As data)
   Set dta = kd
   ParseObject_init
End Sub
'-----------------------------------
Public Sub Execute()
  Dim sortkey As Integer
  Dim a, k As Integer
  kids = dta.getData
    
  For a = 1 To args.Count
    Dim v As ParseObject
    Set v = args(a)
    If TypeOf v Is Multvar Then
      Dim mv As Multvar
      Set mv = v
      Dim mvec As Collection
      Set mvec = mv.getVector()
      For k = mvec.Count To 1 Step -1
        Dim pv As ParseObject
        Set pv = mvec(k)
        sortkey = pv.getValue()
        sortByKey sortkey
      Next k
    Else
      sortkey = v.getValue()
      sortByKey sortkey
    End If
  Next a
End Sub
'----------------------------------------
Private Sub sortByKey(ByVal sortkey As Integer)
  Dim i, j As Integer
  Dim tmp As Kid
  For i = 1 To UBound(kids)
    For j = i + 1 To UBound(kids)
      If (comparev(i, j, sortkey)) Then
        Set tmp = kids(i)
        Set kids(i) = kids(j)
        Set kids(j) = tmp
      End If
    Next j
  Next i
  dta.setData kids
End Sub
'----------------------------------------
Private Function comparev(ByVal i As Integer, ByVal j As Integer, ByVal key As Integer) As Boolean
  Dim cval As Boolean
  Dim pv As New ParseVar
  Select Case key
    Case pv.FRNAME
      cval = kids(i).getFrname() > kids(j).getFrname()
    Case pv.LNAME
      cval = kids(i).getLname() > kids(j).getLname()
    Case pv.CLUB
      cval = kids(i).getClub() > kids(i).getClub()
    Case pv.AGE
      cval = kids(i).getAge() > kids(j).getAge()
    Case pv.TIME
      cval = kids(i).getTime() > kids(j).getTime()
    Case Else
      cval = False
  End Select
  comparev = cval
End Function

Private Sub Command_Execute()
  Execute
End Sub

Private Sub ParseObject_addArg(p As ParseObject)
  args.add p
End Sub

Private Function ParseObject_getType() As Integer
  ParseObject_getType = typ
End Function

Private Function ParseObject_getValue() As Integer
  ParseObject_getValue = value
End Function

Private Sub ParseObject_init()
  value = SORTBY
  typ = VERB_TYPE
End Sub

Private Sub ParseObject_setData(dt As data, ByVal pt As ListBox)
  Set dta = dt
End Sub
