Hi all,
I wrote an application for our poker games. It works great as a timer and stores our points. My problem is that I want to sort the points in order and redisplay along with peoples names, total tournament games, total games.

Here is a snippet of how I load a player and attempt to create an array for the points etc:

'Load YT
Open "C:\Poker\yt.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points
Close #1
Label15.Caption = PlayerName
Label16.Caption = Points
Label17.Caption = TotalGamesPlayed
Label67.Caption = TournamentGames
LeagueTable(0).LName = PlayerName
LeagueTable(0).LPoints = Points
LeagueTable(0).LTourn = TournamentGames
LeagueTable(0).LTotal = TotalGamesPlayed

The rest of the players load up to LeagueTable(14)
I just haven't a clue how to sort and display in a picturebox or text box. Can someone help please?

Thanks,

Mark.

Use a loop to load the results...

Dim x As Integer

For x = 1 To 14
    LeagueTable(x).LName = PlayerName
    LeagueTable(x).LPoints = Points
    LeagueTable(x).LTourn = TournamentGames
    LeagueTable(x).LTotal = TotalGamesPlayed
next x

Hiya,

It's not the loading thats the problem. It's sorting the array in order of highest points first. I need the associated name and other data to move with it then output into a picturebox or similar.

Add the results to a listbox where you have set the listbox "Sorted" property to true. This will sort the data alphabetically/ highest number first style.

Hi, I put the results in a listbox and used, 'Sort' but listboxes sort in strings and not numerical order. My points order then goes 1, 100, 199, 70 where as I need 199,100,70,1.

I used the folling statement to get their names with the points on each player load:
List1.AddItem Points & " YT"

Looks like I just need a little code to sort the listbox in numerical order (Highest at the top) and thats job done.

Correct, its called bubble sort. Try the following code to sort the listbox AFTER all values has been added...

Sub SortListBox

dim counter1 as integer
dim counter2 as integer
dim bufferVal as string

for counter1=0 to listbox.listcount-2
    for counter2=counter1+1 to listbox.listcount-1
        if listbox.list(counter1,0)>listbox.list(counter2,0) then
            bufferval=listbox.list(counter1,0)
            listbox.list(counter1,0)=listbox.list(counter2,0)
            listbox.list(counter2,0)=bufferval
        endif
    next
next
end sub

Hi, sorry to be a pain. My listbox is called List1. When I rename your listbox to list1 in the code I get a compile error that says, 'Wrong number of arguments or invalid property assignment.'
Any idea's what I've done wrong?

I renamed my listbox from List1 to listbox and it says the same error.

I have rewritten the code, tested it and it works fine. Try the following code...

Private Sub SortMyListbox()

Dim count As Integer, i As Integer, x As Integer, c2 As Integer

count = List1.ListCount - 1

Do While count <= 0
    For i = 0 To count
        If List1.List(i) > x Then
            x = List1.List(i)
            c2 = i
        End If
    Next i

    count = count - 1
    List1.RemoveItem (c2)
    List1.AddItem x
    x = 0
Loop
End Sub

''In your command button click event, or any other event where you want to sort the listbox...

Call SortMyListbox

Hiya,
Really appreciate the time you've taken to do the code. I copeied and pasted it in place. Although there are no errors the listbox doesn't change at all. It's still not in order. I did check the names ie List1 etc and all tally up.
Perhaps I could send you the program and if you get a min you could take a look?

Quite strange, I have tested it with different scenarios, was working fine.

That will be fine. Attach it to this thread, I'll take a look and post it back to you. Also attach the text file where the data will be coming from.

I wasn't sure how to attach the files so I've pasted the code from the form with the listbox.

Option Explicit

Dim Firstplace As String
Dim SecondPlace As String
Dim Thirdplace As String
Dim Fourthplace As String
Dim Lastplace As String
Dim PlayerName As String
Dim News As String
Dim entrancefee As Integer
Dim Adminmode As Integer
Dim ImgRand As Integer
Dim tourn As Integer
Dim Playerscore As Integer
Dim Gamesplayed As Integer
Dim total As Integer
Dim Member As String
Dim TournamentGames As Integer
Dim TotalGamesPlayed As Integer
Dim Points As Integer

Private Sub mnuenterplayers_Click()
Frame2.Visible = True
End Sub

'The view stats combo box
Private Sub Command1_Click()
If Combo1 = "2012" Then
Unload Form3
Form3.Visible = True

Else
Label15.Caption = "No Stats Available..."
Label16.Caption = ""
Label17.Caption = ""
Label18.Caption = ""
Label19.Caption = ""
Label20.Caption = ""
Label21.Caption = ""
Label22.Caption = ""
Label23.Caption = ""
Label24.Caption = ""
Label25.Caption = ""
Label26.Caption = ""
Label27.Caption = ""
Label28.Caption = ""
Label29.Caption = ""
Label30.Caption = ""
Label31.Caption = ""
Label32.Caption = ""
Label33.Caption = ""
Label34.Caption = ""
Label35.Caption = ""
Label36.Caption = ""
Label37.Caption = ""
Label38.Caption = ""
Label39.Caption = ""
Label40.Caption = ""
Label41.Caption = ""
Label42.Caption = ""
Label43.Caption = ""
Label44.Caption = ""
Label45.Caption = ""
Label46.Caption = ""
Label47.Caption = ""
Label48.Caption = ""
Label49.Caption = ""
Label50.Caption = ""
Label54.Caption = ""
Label55.Caption = ""
Label56.Caption = ""
Label57.Caption = ""
Label58.Caption = ""
Label59.Caption = ""
Label60.Caption = ""
Label61.Caption = ""
Label62.Caption = ""
Label63.Caption = ""
Label64.Caption = ""
Label65.Caption = ""
Label67.Caption = ""
Label68.Caption = ""
Label69.Caption = ""
Label70.Caption = ""
Label71.Caption = ""
Label72.Caption = ""
Label73.Caption = ""
Label74.Caption = ""
Label75.Caption = ""
Label76.Caption = ""
Label77.Caption = ""
Label78.Caption = ""
Label80.Caption = ""
Label81.Caption = ""
Label82.Caption = ""
Label83.Caption = ""
Label84.Caption = ""
Label85.Caption = ""
Label86.Caption = ""
Label87.Caption = ""
Label88.Caption = ""
Label89.Caption = ""
Label90.Caption = ""
Label91.Caption = ""
Label92.Caption = ""
Label112.Caption = ""
Label113.Caption = ""
Label114.Caption = ""
Label115.Caption = ""
Label116.Caption = ""
Label117.Caption = ""
Label119.Caption = ""
Label120.Caption = ""
Label121.Caption = ""
Label122.Caption = ""
Label123.Caption = ""
Label124.Caption = ""
End If
End Sub

Private Sub Command2_Click()
Dim count As Integer, i As Integer, x As Integer, c2 As Integer
count = List1.ListCount - 1
Do While count <= 0
For i = 0 To count
If List1.List(i) > x Then
x = List1.List(i)
c2 = i
End If
Next i
count = count - 1
List1.RemoveItem (c2)
List1.AddItem x
x = 0
Loop
End Sub

Private Sub Command3_Click()
If Text1.Text = "westham" Then
    Text1.Text = ""
    Frame7.Visible = False
    Form7.Visible = True
    Adminmode = 1
    Label111.Caption = "Administrator Mode"
Else: MsgBox "Incorrect Passcode!"
Frame7.Visible = False
Text1.Text = ""
End If
End Sub

Private Sub Command4_Click()
Frame7.Visible = False
End Sub

Private Sub Form_Load()
Adminmode = 0

'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
If Member = "Platnium" Then
    Image6.Picture = Image19
    Image6.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image6.Picture = Image20
    Image6.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image6.Picture = Image21
    Image6.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image6.Picture = Image22
    Image6.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Morbid
Open "C:\Poker\morbid.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label18.Caption = PlayerName
Label19.Caption = Points
Label20.Caption = TotalGamesPlayed
Label68.Caption = TournamentGames
If Member = "Platnium" Then
    Image8.Picture = Image19
    Image8.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image8.Picture = Image20
    Image8.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image8.Picture = Image21
    Image8.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image8.Picture = Image22
    Image8.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Bighead
Open "C:\Poker\bighead.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label21.Caption = PlayerName
Label22.Caption = Points
Label23.Caption = TotalGamesPlayed
Label69.Caption = TournamentGames
If Member = "Platnium" Then
    Image9.Picture = Image19
    Image9.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image9.Picture = Image20
    Image9.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image9.Picture = Image21
    Image9.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image9.Picture = Image22
    Image9.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Woody
Open "C:\Poker\woody.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label24.Caption = PlayerName
Label25.Caption = Points
Label26.Caption = TotalGamesPlayed
Label70.Caption = TournamentGames
If Member = "Platnium" Then
    Image10.Picture = Image19
    Image10.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image10.Picture = Image20
    Image10.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image10.Picture = Image21
    Image10.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image10.Picture = Image22
    Image10.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Dog
Open "C:\Poker\dog.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label27.Caption = PlayerName
Label28.Caption = Points
Label29.Caption = TotalGamesPlayed
Label71.Caption = TournamentGames
If Member = "Platnium" Then
    Image11.Picture = Image19
    Image11.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image11.Picture = Image20
    Image11.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image11.Picture = Image21
    Image11.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image11.Picture = Image22
    Image11.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Darryl
Open "C:\Poker\darryl.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label30.Caption = PlayerName
Label31.Caption = Points
Label32.Caption = TotalGamesPlayed
Label72.Caption = TournamentGames
If Member = "Platnium" Then
    Image12.Picture = Image19
    Image12.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image12.Picture = Image20
    Image12.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image12.Picture = Image21
    Image12.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image12.Picture = Image22
    Image12.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load E Honda
Open "C:\Poker\ehonda.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label33.Caption = PlayerName
Label34.Caption = Points
Label35.Caption = TotalGamesPlayed
Label73.Caption = TournamentGames
If Member = "Platnium" Then
    Image13.Picture = Image19
    Image13.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image13.Picture = Image20
    Image13.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image13.Picture = Image21
    Image13.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image13.Picture = Image22
    Image13.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Bandit
Open "C:\Poker\bandit.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label36.Caption = PlayerName
Label37.Caption = Points
Label38.Caption = TotalGamesPlayed
Label74.Caption = TournamentGames
If Member = "Platnium" Then
    Image14.Picture = Image19
    Image14.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image14.Picture = Image20
    Image14.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image14.Picture = Image21
    Image14.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image14.Picture = Image22
    Image14.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Dyksey
Open "C:\Poker\dyksey.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label39.Caption = PlayerName
Label40.Caption = Points
Label41.Caption = TotalGamesPlayed
Label75.Caption = TournamentGames
If Member = "Platnium" Then
    Image15.Picture = Image19
    Image15.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image15.Picture = Image20
    Image15.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image15.Picture = Image21
    Image15.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image15.Picture = Image22
    Image15.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Lucock
Open "C:\Poker\lucock.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label42.Caption = PlayerName
Label43.Caption = Points
Label44.Caption = TotalGamesPlayed
Label76.Caption = TournamentGames
If Member = "Platnium" Then
    Image16.Picture = Image19
    Image16.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image16.Picture = Image20
    Image16.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image16.Picture = Image21
    Image16.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image16.Picture = Image22
    Image16.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Hooter
Open "C:\Poker\hooter.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label45.Caption = PlayerName
Label46.Caption = Points
Label47.Caption = TotalGamesPlayed
Label77.Caption = TournamentGames
If Member = "Platnium" Then
    Image17.Picture = Image19
    Image17.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image17.Picture = Image20
    Image17.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image17.Picture = Image21
    Image17.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image17.Picture = Image22
    Image17.ToolTipText = "Bronze"
End If
List1.AddItem Points

'Load Stonch
Open "C:\Poker\stonch.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label48.Caption = PlayerName
Label49.Caption = Points
Label50.Caption = TotalGamesPlayed
Label78.Caption = TournamentGames
If Member = "Platnium" Then
    Image18.Picture = Image19
    Image18.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image18.Picture = Image20
    Image18.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image18.Picture = Image21
    Image18.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image18.Picture = Image22
    Image18.ToolTipText = "Bronze"
End If
List1.AddItem Points & "Stonch"

'Load Jason N
Open "C:\Poker\jasonn.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label113.Caption = PlayerName
Label117.Caption = Points
Label116.Caption = TotalGamesPlayed
Label114.Caption = TournamentGames
If Member = "Platnium" Then
    Image2.Picture = Image19
    Image2.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image2.Picture = Image20
    Image2.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image2.Picture = Image21
    Image2.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image2.Picture = Image22
    Image2.ToolTipText = "Bronze"
End If
List1.AddItem Points & " Jason N"

'Load Jonsey
Open "C:\Poker\jonsey.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label120.Caption = PlayerName
Label124.Caption = Points
Label123.Caption = TotalGamesPlayed
Label121.Caption = TournamentGames
If Member = "Platnium" Then
    Image23.Picture = Image19
    Image23.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image23.Picture = Image20
    Image23.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image23.Picture = Image21
    Image23.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image23.Picture = Image22
    Image23.ToolTipText = "Bronze"
End If
List1.AddItem Points & " Jonsey"

'Load John Deeble
Open "C:\Poker\johnd.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label128.Caption = PlayerName
Label132.Caption = Points
Label131.Caption = TotalGamesPlayed
Label129.Caption = TournamentGames
If Member = "Platnium" Then
    Image3.Picture = Image19
    Image3.ToolTipText = "Platnium"
ElseIf Member = "Gold" Then
    Image3.Picture = Image20
    Image3.ToolTipText = "Gold"
ElseIf Member = "Silver" Then
    Image3.Picture = Image21
    Image3.ToolTipText = "Silver"
ElseIf Member = "Bronze" Then
    Image3.Picture = Image22
    Image3.ToolTipText = "Bronze"
End If
List1.AddItem Points & " John D"
'********************************************************

'Sort the table out in order
SortMyListbox

'Load the entrance fee
Open "C:\Poker\entrancefee.dat" For Input As #1
Input #1, entrancefee
Close #1
Label109.Caption = "£" & entrancefee

'Load the news
Open "C:\Poker\news.dat" For Input As #1
Input #1, News
Close #1
Label52.Caption = News

'Load the last game played results
Open "C:\Poker\lastgame.dat" For Input As #1
Input #1, Firstplace, SecondPlace, Thirdplace, Fourthplace, Lastplace
Close #1

'Populate the Firstplace and Second place labels
Label4.Caption = Firstplace
Label5.Caption = SecondPlace
Label10.Caption = Thirdplace
Label12.Caption = Fourthplace
Label14.Caption = Lastplace

Combo1.AddItem "2012"
Combo1.AddItem "2013"
Combo1.AddItem "2014"
Combo1.AddItem "2015"
Combo1.AddItem "2016"
Combo1.AddItem "2017"
Combo1.AddItem "2018"
Combo1.AddItem "2019"
Combo1.AddItem "2020"

If Combo1 = "2012" Then
'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

'Load Morbid
Open "C:\Poker\morbid.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label18.Caption = PlayerName
Label19.Caption = Points
Label20.Caption = TotalGamesPlayed
Label68.Caption = TournamentGames

'Load Bighead
Open "C:\Poker\bighead.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label21.Caption = PlayerName
Label22.Caption = Points
Label23.Caption = TotalGamesPlayed
Label69.Caption = TournamentGames

'Load Woody
Open "C:\Poker\woody.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label24.Caption = PlayerName
Label25.Caption = Points
Label26.Caption = TotalGamesPlayed
Label70.Caption = TournamentGames

'Load Dog
Open "C:\Poker\dog.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label27.Caption = PlayerName
Label28.Caption = Points
Label29.Caption = TotalGamesPlayed
Label71.Caption = TournamentGames

'Load Darryl
Open "C:\Poker\darryl.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label30.Caption = PlayerName
Label31.Caption = Points
Label32.Caption = TotalGamesPlayed
Label72.Caption = TournamentGames

'Load E Honda
Open "C:\Poker\ehonda.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label33.Caption = PlayerName
Label34.Caption = Points
Label35.Caption = TotalGamesPlayed
Label73.Caption = TournamentGames

'Load Bandit
Open "C:\Poker\bandit.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label36.Caption = PlayerName
Label37.Caption = Points
Label38.Caption = TotalGamesPlayed
Label74.Caption = TournamentGames

'Load Dyksey
Open "C:\Poker\dyksey.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label39.Caption = PlayerName
Label40.Caption = Points
Label41.Caption = TotalGamesPlayed
Label75.Caption = TournamentGames

'Load Lucock
Open "C:\Poker\lucock.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label42.Caption = PlayerName
Label43.Caption = Points
Label44.Caption = TotalGamesPlayed
Label76.Caption = TournamentGames

'Load Hooter
Open "C:\Poker\hooter.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label45.Caption = PlayerName
Label46.Caption = Points
Label47.Caption = TotalGamesPlayed
Label77.Caption = TournamentGames

'Load Stonch
Open "C:\Poker\stonch.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label48.Caption = PlayerName
Label49.Caption = Points
Label50.Caption = TotalGamesPlayed
Label78.Caption = TournamentGames

'Load Jason N
Open "C:\Poker\jasonn.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label113.Caption = PlayerName
Label117.Caption = Points
Label116.Caption = TotalGamesPlayed
Label114.Caption = TournamentGames

'Load Jonsey
Open "C:\Poker\jonsey.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label120.Caption = PlayerName
Label124.Caption = Points
Label116.Caption = TotalGamesPlayed
Label121.Caption = TournamentGames

'Load John Deeble
Open "C:\Poker\johnd.pok" For Input As #1
Input #1, PlayerName, TournamentGames, TotalGamesPlayed, Points, Member
Close #1
Label128.Caption = PlayerName
Label132.Caption = Points
Label131.Caption = TotalGamesPlayed
Label129.Caption = TournamentGames
'*********END OF NEW CODE*************************
End If

Dim YTAvg As Integer
If Label67 > 0 Then
    YTAvg = Label16 / Label67
    Label80.Caption = YTAvg
Else
    Label80.Caption = 0
End If

Dim MorbidAvg As Integer
If Label68 > 0 Then
    MorbidAvg = Label19 / Label68
    Label81.Caption = MorbidAvg
Else
    Label81.Caption = 0
End If

Dim BigheadAvg As Integer
If Label69 > 0 Then
    BigheadAvg = Label22 / Label69
    Label82.Caption = BigheadAvg
Else
    Label82.Caption = 0
End If

Dim WoodyAvg As Integer
If Label70 > 0 Then
    WoodyAvg = Label25 / Label70
    Label84.Caption = WoodyAvg
Else
    Label84.Caption = 0
End If

Dim DogAvg As Integer
If Label71 > 0 Then
    DogAvg = Label28 / Label71
    Label85.Caption = DogAvg
Else
    Label85.Caption = 0
End If

Dim DarrylAvg As Integer
If Label72 > 0 Then
    DarrylAvg = Label31 / Label72
    Label86.Caption = DarrylAvg
Else
    Label86.Caption = 0
End If

Dim EHondaAvg As Integer
If Label73 > 0 Then
    EHondaAvg = Label34 / Label73
    Label87.Caption = EHondaAvg
Else
    Label87.Caption = 0
End If

Dim BanditAvg As Integer
If Label74 > 0 Then
    BanditAvg = Label37 / Label74
    Label88.Caption = BanditAvg
Else
    Label88.Caption = 0
End If

Dim DykseyAvg As Integer
If Label75 > 0 Then
    DykseyAvg = Label40 / Label75
    Label89.Caption = DykseyAvg
Else
    Label89.Caption = 0
End If

Dim LucockAvg As Integer
If Label76 > 0 Then
    LucockAvg = Label43 / Label76
    Label90.Caption = LucockAvg
Else
    Label90.Caption = 0
End If

Dim HooterAvg As Integer
If Label77 > 0 Then
    HooterAvg = Label46 / Label77
    Label91.Caption = HooterAvg
Else
    Label91.Caption = 0
End If

Dim StonchAvg As Integer
If Label78 > 0 Then
    StonchAvg = Label49 / Label78
    Label92.Caption = StonchAvg
Else
    Label92.Caption = 0
End If

Dim JasonNAvg As Integer
If Label114 > 0 Then
    JasonNAvg = Label117 / Label114
    Label115.Caption = JasonNAvg
Else
    Label115.Caption = 0
End If

Dim JonseyAvg As Integer
If Label121 > 0 Then
    JonseyAvg = Label124 / Label121
    Label122.Caption = JonseyAvg
Else
    Label122.Caption = 0
End If

Dim JDeebleAvg As Integer
If Label129 > 0 Then
    JDeebleAvg = Label132 / Label129
    Label130.Caption = JDeebleAvg
Else
    Label130.Caption = 0
End If

'Lets compare the points to see whos in first place!

Dim PointsArray(15) As Integer
PointsArray(0) = Label16
PointsArray(1) = Label19
PointsArray(2) = Label22
PointsArray(3) = Label25
PointsArray(4) = Label28
PointsArray(5) = Label31
PointsArray(6) = Label34
PointsArray(7) = Label37
PointsArray(8) = Label40
PointsArray(9) = Label43
PointsArray(10) = Label46
PointsArray(11) = Label49
PointsArray(12) = Label117
PointsArray(13) = Label124
PointsArray(14) = Label132

Dim IntX As Long
Dim lngY As Long
Dim intTemp As Integer
Dim blnExchangeMade As Boolean
blnExchangeMade = True
Do While blnExchangeMade
blnExchangeMade = False
For lngY = LBound(PointsArray) To (UBound(PointsArray) - 1)
If PointsArray(lngY) > PointsArray(lngY + 1) Then
'exchange the items
intTemp = PointsArray(lngY)
PointsArray(lngY) = PointsArray(lngY + 1)
PointsArray(lngY + 1) = intTemp
blnExchangeMade = True
End If
Next
Loop

For IntX = 0 To 15
Text2.Text = "Current 1st Place:" & PointsArray(15) & "    Current Second Place:" & PointsArray(14) & "    Current Third Place:" & PointsArray(13)
Next

Label54.Caption = 0
Label55.Caption = 0
Label56.Caption = 0
Label57.Caption = 0
Label58.Caption = 0
Label59.Caption = 0
Label60.Caption = 0
Label61.Caption = 0
Label62.Caption = 0
Label63.Caption = 0
Label64.Caption = 0
Label65.Caption = 0
Label112.Caption = 0
Label119.Caption = 0
Label127.Caption = 0

Label93.Caption = "YT"
Label94.Caption = "Morbid"
Label95.Caption = "Big Head"
Label96.Caption = "Woody"
Label97.Caption = "Dog"
Label98.Caption = "Darryl"
Label99.Caption = "E Honda"
Label100.Caption = "Bandit"
Label101.Caption = "Dyksey"
Label102.Caption = "Lucock"
Label103.Caption = "Hooter"
Label104.Caption = "Stonch"
Label118.Caption = "Jason N"
Label125.Caption = "Jonsey"
Label135.Caption = "John D"

End Sub

Private Sub Image3_Click()
Unload Form3
Form3.Show

Form1.Visible = True
End Sub

Private Sub Frame4_DragDrop(Source As Control, x As Single, Y As Single)

End Sub

Private Sub Label111_Click()
Adminmode = 0
Label111.Caption = "Standard User Mode"
End Sub

Private Sub mnuabout_Click()
Form2.Visible = True
End Sub

Private Sub mnudisableanimation_Click()
Timer1.Enabled = False
Image1.Picture = Image23
End Sub

Private Sub mnueditstats_Click()
If Adminmode = 1 Then
    Form7.Visible = True
Else
Frame7.Visible = True
End If
End Sub

Private Sub mnuentrancefee_Click()
Form8.Visible = True
End Sub

Private Sub mnuplayers_Click()

End Sub

Private Sub mnulockerroom_Click()
Form10.Visible = True
End Sub

Private Sub mnumemberedit_Click()
Form6.Visible = True
End Sub

Private Sub mnunews_Click()
Form5.Visible = True
End Sub

Private Sub mnupokertimer_Click()
Unload Form3
Form3.Show

Form1.Visible = True
End Sub

Private Sub mnurefresh_Click()
Unload Form3
Form3.Show
End Sub

Private Sub mnushutdown_Click()
End
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 2 Then
    PopupMenu mnufile
End If

End Sub

Private Sub mnuwinninghands_Click()
Form9.Show
End Sub

Private Sub Timer1_Timer()

If ImgRand = 0 Then
Image1.Picture = Image24
ImgRand = 1
Else
ImgRand = 0
Image1.Picture = Image23
End If
End Sub

Private Sub SortMyListbox()
Dim count As Integer, i As Integer, x As Integer, c2 As Integer
count = List1.ListCount - 1
Do While count <= 0
For i = 0 To count
If List1.List(i) > x Then
x = List1.List(i)
c2 = i
End If
Next i
count = count - 1
List1.RemoveItem (c2)
List1.AddItem x
x = 0
Loop
End Sub

In load form event -

'Sort the table out in order
SortMyListbox - incorrect...

change to -

'Sort the table out in order
Call SortMyListbox

You should try and use proper naming conventions, Label1 to Label... etc is quite confusing. Also use indexes - Label1(0), Label1(2)... Only a tip, will not affect your code.

The problem in the sortlist sub was -
1) Do while count < should be > (larger, not smaller)
Also, no reference to a listbox.

I have removed all your code except for what we needed here, this is what works fine now, getting the list sorted. HOWEVER, when there are duplicates, say like 12, it will sort all 12's below each other, you will not know which one belongs to which player. You need more code here to get it properly sorted... Different question/thread from this one.

Option Explicit

Dim Firstplace As String
Dim SecondPlace As String
Dim Thirdplace As String
Dim Fourthplace As String
Dim Lastplace As String
Dim PlayerName As String
Dim News As String
Dim entrancefee As Integer
Dim Adminmode As Integer
Dim ImgRand As Integer
Dim tourn As Integer
Dim Playerscore As Integer
Dim Gamesplayed As Integer
Dim total As Integer
Dim Member As String
Dim TournamentGames As Integer
Dim TotalGamesPlayed As Integer
Dim Points As Integer

Private Sub cmdSort_Click()

Call SortMyListbox(List1)
End Sub

Private Sub Form_Load()

''Player 1
List1.AddItem "1"
List1.AddItem "100"
List1.AddItem "199"
List1.AddItem "70"

''Player 2
List1.AddItem "1"
List1.AddItem "125"
List1.AddItem "173"
List1.AddItem "38"

''Player 3
List1.AddItem "3"
List1.AddItem "99"
List1.AddItem "27"
List1.AddItem "118"

''Player 4
List1.AddItem "1"
List1.AddItem "101"
List1.AddItem "157"
List1.AddItem "68"
End Sub

Private Sub SortMyListbox(lstSort As ListBox)

Dim count As Integer, i As Integer, x 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)
            c2 = i
        End If
    Next i

    count = count - 1
    lstSort.RemoveItem (c2)
    lstSort.AddItem x

    x = 0
Loop
End Sub

Hiya,

Thanks again for your time. It says I have a type mismatch with this line:

If lstSort.List(i) > x Then

Any ideas why thats flagging up fella?

My bad, the lstSort listindex was not set, hence the error - meaning that it was looking for an index that did not exist...

Add the following -

For i = 0 To count
    lstSort.ListIndex = i
        If lstSort.List(i) > x Then
            x = lstSort.List(i)
            c2 = i
        End If
    Next i

It sorts the numbers perfectly! Thank you very much. The reason for the error was the strings I had on the end ie:

List1.additem Points & "Carl"

If I remove the strings the numbers sort perfectly thanks to you. I don't suppose you know how I could add a string to the numbers do you?

Lol, no problem, all a pleasure. :)

Mark this thread as solved and open a new thread, its actually quite easy to add the strings by making use of a second list box.

How do I mark as solved?

At the bottom you will see 2 grey buttons - "Stop Watching this Article AND Mark Question Solved". Click on "Mark Question Solved"

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.