VB League Table Picture Box Text Arrangment.. :)
Hello, this is my first post in this form :wave:
I have a question i am not sure can be answered. I am very new to visual basic and have just started studying it in A Level Computing (UK). Basically our teachers a bit of a nob and dont help us because he cant... :)
Anyway.. I am currently building a program for my final project. Its a league table ( the usual 3 points for a win 1 for a draw etc ) like football (soccer) etc.
The table has a text file where the program picks up the team names etc and has them printed out on a picture box. I then go to my fixtures section of the program and process a fixture which updates the text file and the picture box accoring to who won (will give winners 3 points etc).
I then have a table updated perfectly everything going right on the picture box but i do not know if i can arrange the points by highest (have the team with the most points at the top lowest at the bottom). In the text file the teams are lined up like this...
Arsenal
0
0
0
0
0
Chelsea
1
0
1
0
1
Man Utd
0
0
0
0
0
Liverpool
3
0
3
0
3
Tottenham
3
0
3
0
3
Wigan
0
0
0
0
0
Bolton
1
0
1
0
1
Man City
0
0
0
0
0
Blackburn
0
0
0
0
0
West Ham
0
0
0
0
0
Charlton
0
0
0
0
0
Fulham
0
0
0
0
0
Newcastle
0
0
0
0
0
Everton
0
0
0
0
0
Aston Villa
0
0
0
0
0
West Brom
0
0
0
0
0
Middlesboro
0
0
0
0
0
Portsmouth
0
0
0
0
0
Birmingham
0
0
0
0
0
Sunderland
0
0
0
0
0
As you can see some have been updated..
the first zero repesents Games Played
the second Games Won
third Games Drawn
fourth Games Lost
fifth Points...
Its the fifth zero that i need arranged..
This is what this looks like printed on the picturebox...
CLICK HERE
Im sorry if this is hard to understand but i am very new as im sure many people are on here.
Thanks Alot for anytime you spend on trying to answer this question.
Moka
Re: VB League Table Picture Box Text Arrangment.. :)
Welcome to VB Forums!
I don't have the time time now to actually do the code, but you could create a user defined type like this
VB Code:
Option Explicit
Private Type League
Team As String
Played As Integer
Won As Integer
Drawn As Integer
Lost As Integer
Points As Integer
End Type
And then create an array like this to hold the data until you want to print it.
Dim LeageTable(18) As League
And once you have all the data you could do a bubble sort (which you can Search for examples of) and then print from the sorted array.
Re: VB League Table Picture Box Text Arrangment.. :)
I thought the best way would be to upload my work so someone could maybe download and have a look to see if they know how i would arrange the League Table via Points.
Thanks for anyone who takes the time in helping me out here...
CLICK HERE TO DOWNLOAD TABLE
Re: VB League Table Picture Box Text Arrangment.. :)
Did you understand my suggestion?
Re: VB League Table Picture Box Text Arrangment.. :)
no sorry i didnt, i have never done nethink like this before and i have no idea what to do with what you told me. If you have time could you explain it more?
i already have an array. can i arrange information in a text file before it gets printed onto a picturebox?
Thanks
Moka
Re: VB League Table Picture Box Text Arrangment.. :)
VB Code:
Option Explicit
Private Type League
Team As String
Played As Integer
Won As Integer
Drawn As Integer
Lost As Integer
Points As Integer
End Type
Private Sub Form_Load() ' You wouldn't do this in Form_Load
Dim LeageTable(18) As League
Dim Temp As League
Dim lngIndex As Long
Dim bSwapped As Boolean
'Add some test data (I know the values don't make sense)
LeageTable(0).Team = "Arsenal"
LeageTable(0).Played = 0
LeageTable(0).Won = 0
LeageTable(0).Lost = 0
LeageTable(0).Drawn = 0
LeageTable(0).Points = 3
LeageTable(1).Team = "Liverpool"
LeageTable(1).Played = 0
LeageTable(1).Won = 0
LeageTable(1).Lost = 0
LeageTable(1).Drawn = 0
LeageTable(1).Points = 5
LeageTable(2).Team = "Tottenham"
LeageTable(2).Played = 0
LeageTable(2).Won = 0
LeageTable(2).Lost = 0
LeageTable(2).Drawn = 0
LeageTable(2).Points = 2
LeageTable(3).Team = "Man Utd"
LeageTable(3).Played = 0
LeageTable(3).Won = 0
LeageTable(3).Lost = 0
LeageTable(3).Drawn = 0
LeageTable(3).Points = 1
'sort the data
bSwapped = True
Do Until bSwapped = False
bSwapped = False
For lngIndex = 0 To 2 ' you would use 17
If LeageTable(lngIndex).Points <= LeageTable(lngIndex + 1).Points Then
' store the lower value data to be replaced
Temp.Drawn = LeageTable(lngIndex).Drawn
Temp.Lost = LeageTable(lngIndex).Lost
Temp.Played = LeageTable(lngIndex).Played
Temp.Points = LeageTable(lngIndex).Points
Temp.Team = LeageTable(lngIndex).Team
Temp.Won = LeageTable(lngIndex).Won
' move the higher values up one in the array
LeageTable(lngIndex).Drawn = LeageTable(lngIndex + 1).Drawn
LeageTable(lngIndex).Lost = LeageTable(lngIndex + 1).Lost
LeageTable(lngIndex).Played = LeageTable(lngIndex + 1).Played
LeageTable(lngIndex).Points = LeageTable(lngIndex + 1).Points
LeageTable(lngIndex).Team = LeageTable(lngIndex + 1).Team
LeageTable(lngIndex).Won = LeageTable(lngIndex + 1).Won
' replace the old higher value data with the saved lower values
LeageTable(lngIndex + 1).Drawn = Temp.Drawn
LeageTable(lngIndex + 1).Lost = Temp.Lost
LeageTable(lngIndex + 1).Played = Temp.Played
LeageTable(lngIndex + 1).Points = Temp.Points
LeageTable(lngIndex + 1).Team = Temp.Team
LeageTable(lngIndex + 1).Won = Temp.Won
bSwapped = True
End If
Next
Loop
' The array is now sorted with the highest point teams at the top and you
' can print that data to the picture.
End Sub