[Source]Sorting a ListView

Discussion in 'Programming General' started by Covey, Nov 5, 2007.

[Source]Sorting a ListView
  1. Unread #1 - Nov 5, 2007 at 5:33 AM
  2. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [Source]Sorting a ListView

    I had to make a procedure to sort a listview, so if anyone else needs one you can edit this.
    This was a custom function for a program i was making for cool372. It was required to sort the top 10 highscores with the format of "blah blah - 99:99:99".

    Code:
    Private Sub LoadnSortHighscores(lstListBox As ListBox, strPath As String)
        Dim fFile As Long, strData As String, i As Long, strLines() As String, a As Long
        fFile = FreeFile
        Open strPath For Input As fFile
            strData = Input(LOF(fFile), fFile)
        Close fFile
        strLines() = Split(strData, vbCrLf)
        Do Until lstListBox.ListCount >= 10
        For i = 0 To 9
            For a = 0 To 9
                If Not a = i Or Not Val(strLines(a)) = "0" Then
                    If Not Val(Replace(Split(strLines(i), "-")(1), ":", "")) >= Val(Replace(Split(strLines(a), "-")(1), ":", "")) Then
                        GoTo SkipThis
                    End If
                End If
            Next a
            If Not Val(Replace(Split(strLines(i), "-")(1), ":", "")) = "0" Then
                lstListBox.AddItem strLines(i)
            End If
            strLines(i) = "0-0"
    SkipThis:
        Next i
        Loop
    End Sub
     
  3. Unread #2 - Nov 5, 2007 at 5:51 AM
  4. Darthatron
    Joined:
    May 22, 2006
    Posts:
    1,612
    Referrals:
    3
    Sythe Gold:
    0

    Darthatron Massive Troll
    Retired Sectional Moderator Visual Basic Programmers

    [Source]Sorting a ListView

    Nice Covey, thanks. I could use this... =)
     
  5. Unread #3 - Nov 5, 2007 at 12:38 PM
  6. Covey
    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    [Source]Sorting a ListView

    uhh, and i mean listbox not listview.
     
< [Function] GetCombatLevel & GetCombatClass | Released [VB6] Functions >

Users viewing this thread
1 guest


 
 
Adblock breaks this site