Hiya,
Andre kindly showed me how to put my points into a listbox and sort in numerical order decending. I need a way, (Perhaps another list box) of adding a string, (Players Name) next to the points after they are sorted so we can clearly see who's first etc.

Here's how I load a player and output his points to the listbox.

'Load YT
Open "C:\Poker\yt.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label15.Caption = PlayerName
Label16.Caption = Points
Label17.Caption = TotalGamesPlayed
Label67.Caption = TournamentGames
List1.AddItem Points

I load the other 14 players the same way. All the points appear in list1 then are sorted by the new bit of code. How can I get 'YT' next to his points etc etc?

Thanks in advance.

Hi Mark,

Just add another listbox to your form, lstNames...
When adding the scores, add the name to this listbox -

lstNames.AddItem PlayerName

Remember to loop through it to get all names loaded as you did with their points...

Now, AFTER sorting listbox points, sort the names in the same go...

Private Sub SortMyListbox(lstSort As ListBox, lstName As Listbox)
Dim count As Integer, countName as Integer, i As Integer, x As Integer, xName As Integer, c2 As Integer
count = lstSort.ListCount - 1

Do While count >= 0
    For i = 0 To count
        If lstSort.List(i) > x Then
            x = lstSort.List(i)
            xName = lstName.List(i)
            c2 = i
        End If
    Next i

    count = count - 1
    lstSort.RemoveItem (c2)
    lstName.RemoveItem (c2)
    lstSort.AddItem x
    lstName.AddItem xName
    x = 0
    xName = 0
Loop
End Sub

Now, change your call statement to...

Call SortMyListbox(lstSort As ListBox, lstName As Listbox)

''Depending what you called your listboxes...

I have a type mismatch error on line:

xName = List2.List(i)

Also the Call statement wont accept the syntax. It does accept:
Call SortmyListBox(List1, List2)

Can you help buddy?

That is because you have named your Listboxes List1 and List2. I used (the correctway) conventional naming - lstSort and lstName....

Change the code a bit -

Dim count As Integer, countName as Integer, i As Integer, x As Integer, xName As Integer, c2 As Integer, c3 As Integer

Do While count >= 0
    For i = 0 To count 
        If lstSort.List(i) > x Then
            x = lstSort.List(i)
            lstName.ListIndex = lstSort.ListIndex
            xName = lstName.Text
            c2 = i
            c3 = lstName.ListIndex
        End If
    Next i
    count = count - 1
    lstSort.RemoveItem (c2)
    lstName.RemoveItem (c3)
    lstSort.AddItem x
    lstName.AddItem xName
    x = 0
    xName = 0
Loop

Hi mate, I renamed the Listboxes lstSort and Lstname. I got the same error on line:

xName = lstName.List(i)

It doesn't like the call line either. It says, 'Expected: List seperator Or )' for line:
Call SortMyListbox(lstSort As Listbox, lstName As Listbox)

Im well confused.

Found the prob, I changed XName as a string and all works GREAT! Cheers buddy!
Your are a star and been a massive help.

commented: pleasure +12

My pleasure mate. Glad you got the "knack" of what the code does. :) Some kudos there for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.