' Written on July 24th, 2002 by Mark Jacobson for 810:030 example
' UNIplayersVolleyBallver2.vbp is a revision of UNIplayersVolleyBall.vbp
' It was written from at 6 p.m. on Thursday, July 25th.
' THIS VERSION USES LISTBOX CONTROLS instead of using the Selection 
Sort...

Function heightToInches(feetInches As String) As Integer
    inches = 12 * Val(Left(feetInches, 1)) + _
             Val(Mid(feetInches, 3))
    heightToInches = inches
End Function

' Here is an alternative approach to sorting the players by height
' Using a ListBox named lstByHeight with its Sorted property = True
' makes it simple to display the players sorted into Ascending Order
' by height.

Private Sub cmdShowByHeight_Click()
    Cls
    Dim playerHeight As String
        
    lstByHeight.Visible = True
    lstByHeight2.Visible = False
    
    If lstByHeight.ListCount > 0 Then Exit Sub
    
    Open "Z:\web\UNIplayers.txt" For Input As #10
         
    Do Until EOF(10)
        Input #10, playerNumber, playerName, playerHeight
        spaces = ""
        For i = 1 To 17 - Len(playerName)
            spaces = spaces & " "
        Next i
        lstByHeight.AddItem heightToInches(playerHeight) & " " & _
                            playerName & spaces & playerHeight
    Loop
    
    Close #10
End Sub

' The ListBox lstByHeight2 has its Sorted property = False, so it can be
' sorted into descending order by Height, instead of Ascending Order.

Private Sub cmdShowByHeightDescending_Click()
    Cls
    If lstByHeight.ListCount = 0 Then cmdShowByHeight_Click
    
    lstByHeight.Visible = False
    lstByHeight2.Visible = True
    
    If lstByHeight2.ListCount > 0 Then Exit Sub
    
    
    For i = 0 To lstByHeight.ListCount - 1
        
        player = lstByHeight.List(i)
        heightInches = Left(player, 2)
        
        lstByHeight2.AddItem Mid(player, 4) & _
                             IIf(heightInches = "70" Or _
                                 heightInches = "71", " ", "  ") & _
                             Left(player, 2)
    Next i
    
    n = lstByHeight2.ListCount
    
    For i = 0 To n - 1
        theItem = lstByHeight2.List(n - 1)
        lstByHeight2.AddItem theItem, i
        lstByHeight2.RemoveItem n
    Next i
End Sub