PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
VS 2008 Data Sorting And Displaying-VBForums
Results 1 to 6 of 6

Thread: Data Sorting And Displaying

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2014
    Posts
    9

    Data Sorting And Displaying

    Hi,

    I am making a basketball app for my son.

    What I trying to achieve is the following

    8 Players

    8 Labels with that display the accumulating score "Total Score" (These are the ones I want to rank)

    As these scores change, I want to display their rank underneath in another label "Player Rank" (1 to 8)

    Any help would be appreciated, please make answers simplistic for me

    Thankyou

    Andrew



    Name:  94 Feb. 18 13.45.png
Views: 129
Size:  12.9 KB

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,673

    Re: Data Sorting And Displaying

    The specifics depend on how you have implemented things but you really ought to have a type defined that represents a Player. You can then simply sort a list of those objects by the Score property and then loop through that list and set the Rank property, e.g.
    vb.net Code:
    1. Public Class Player
    2.  
    3.     Public Property Score As Double
    4.  
    5.     Public Property Rank As Integer
    6.  
    7.     'Other members here.
    8.  
    9. End Class
    vb.net Code:
    1. Dim players As Player() = {New Player, New Player, New Player, New Player, New Player, New Player, New Player, New Player}
    2.  
    3. '...
    4.  
    5. Array.Sort(players, Function(p1, p2) p1.Score.CompareTo(p2.SCore))
    6.  
    7. For i = 0 To players.GetUpperBound(0)
    8.     players(i).Rank = i + 1
    9. Next
    You can still do much the same thing even if you don't have a Player class or similar but, if you want something more specific to your implementation, we'd need to know more about your implementation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Registered User
    Join Date
    Jul 2014
    Posts
    9

    Re: Data Sorting And Displaying

    Hi, please see my complete code attached
    As you will see by the coding, I need specific help with this problem

    I am not too worried about consolidating the code etc

    Thankyou

    BasketballStats.txtRegards

    Andrew

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,673

    Re: Data Sorting And Displaying

    Quote Originally Posted by beiag005 View Post
    Hi, please see my complete code attached
    I have no interest in your complete code. I'm only interested in the code specifically relevant to this issue, which you should post directly, much as I have done in post #2. All that is required is a description of how the data for a single player is represented. As I said, you really should define a type to represent a single player and have everything else inside that. If you haven't done that, I'd suggest that you change it so that you do. It will make future maintenance much easier.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Registered User
    Join Date
    Jul 2014
    Posts
    9

    Re: Data Sorting And Displaying

    Thanks for that

    I tried your code above and couldn't get it to work

    Here is what i have tried to do, but no luck however

    Are you able to let me know how to solve this
    Thankyou


    Private Sub btnRank_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRank.Click

    Dim Rank As Integer() = New Integer(7) {}

    Rank(0) = lblPlayerScoreResult1.Text
    Rank(1) = lblPlayerScoreResult2.Text
    Rank(2) = lblPlayerScoreResult3.Text
    Rank(3) = lblPlayerScoreResult4.Text
    Rank(4) = lblPlayerScoreResult5.Text
    Rank(5) = lblPlayerScoreResult6.Text
    Rank(6) = lblPlayerScoreResult7.Text
    Rank(7) = lblPlayerScoreResult8.Text


    System.Array.Sort(Of Integer)(Rank)


    Dim Result As Integer

    For Each Result In Rank

    lblPlayerRank8.Text = (Result)
    lblPlayerRank7.Text = (Result)
    lblPlayerRank6.Text = (Result)
    lblPlayerRank5.Text = (Result)
    lblPlayerRank4.Text = (Result)
    lblPlayerRank3.Text = (Result)
    lblPlayerRank2.Text = (Result)
    lblPlayerRank1.Text = (Result)

    Next

    End Sub

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    100,673

    Re: Data Sorting And Displaying

    What you've got there can't possibly work because there's no relationship between the score and the rank for any individual player. That's why I said that you should have a type that represents a player. That way, when you sort the player objects by score, all the data for each player goes along with that score, including the rank. As it stands, you're not even using ranks at all. You're sorting scores and then putting those scores in the rank Labels.

    You really need to rethink your design. For one thing, you should pretty much NEVER be getting the Text of a Label. Labels are for display purposes, not data storage. You should have all your score data stored somewhere, i.e. an array or collection of some sort, and push it from there to the appropriate Labels for display. If you need to get the score data, you get it from the array or collection, NOT from the Labels.

    You also need to provide a relationship between the various pieces of data for an individual player. That can be done in a number of ways, e.g. concurrent arrays, but the fact that you have at least nine pieces of data per player means that the only efficient and therefore sensible way is to define a type that represents a single player. I'd do that like this:
    vb.net Code:
    1. Public Class Player
    2.  
    3.     Public Property Name As String
    4.     Public Property Rebounds As Integer
    5.     Public Property Steals As Integer
    6.     Public Property Turnovers As Integer
    7.     Public Property GoalsMissed As Integer
    8.     Public Property Assists As Integer
    9.     Public Property Points As Integer
    10.     Public Property Score As Double
    11.     Public Property Rank As Integer
    12.  
    13. End Class
    You can then create a Player array or a List(Of Player) and store all the data for each player in that. You might want a unique ID for each player too, so you can still identify which is which after sorting. You could use the Name for that but I'd sooner go with a sequential numeric ID. Ranking players is then a simple process of doing just what I said: sorting your list of players by Score and then looping through the list and assigning sequential Rank values. You can then push those Rank values to the appropriate Labels. Note that all data manipulation is done on the data store and then pushed to the UI. The UI is for display and user data entry only.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width