Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:29:48+00:00 2026-06-13T00:29:48+00:00

I’m rather new to visual basic and I’m making a text based game for

  • 0

I’m rather new to visual basic and I’m making a text based game for a little project in my spare time. The game will have a scoring system, at the end of the game the user’s score will be stored in a text file. I haven’t written the code to write to the file although im sure appending text isn’t difficult. The problem I’m having is displaying the high scores; I can read them in, I can use Split(“,”), I have even displayed the results in a nice table. The problem I am having is displaying the high scores in order of the actual scores.
This is the code i have to build the score table.(NOTE. Pad() is a function i made to pad spaces to the end of strings, this is so they fit into the table correctly. sytax: Pad(string,length of output))

    Dim FStrm As FileStream
    Dim StrmR As StreamReader
    FStrm = New FileStream("HighScores.txt", FileMode.Open)
    StrmR = New StreamReader(FStrm)
    Dim highScores As New List(Of String)

    While StrmR.Peek <> -1
        highScores.Add(StrmR.ReadLine)
    End While

    FStrm.Close()

    Console.WriteLine("       __________________________________________________________________ ")
    Console.WriteLine("      |       Score       |       Name                                   |")
    Console.WriteLine("      |-------------------|----------------------------------------------|")
    Dim Scores() As String
    For Each score As String In highScores
        Scores = score.Split(",")
        Console.WriteLine("      |  {0}  |  {1}    |", Pad(Scores(0), 15), Pad(Scores(1), 40))
    Next
    Console.WriteLine("      |___________________|______________________________________________| ")

The following is an example of the text file.

2,Zak
10000,Charlie
9999,Shane
90019,Rebecca

Could somebody please help me find a way to sort the lines by the score, maybe I need to take a completely different approach? Thank you very much!

-Charlie

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:29:49+00:00Added an answer on June 13, 2026 at 12:29 am

    I’m a C# guy, but here goes:

    Dim scores As List(Of UserScore)
    Dim lines As String()
    'Read in all lines in one hit.
    lines = File.ReadAllLines("HighScores.txt")
    scores = New List(Of UserScore)
    
    For Each line As String In lines
        Dim tokens As String()
        'Split each line on the comma character.
        tokens = line.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
    
        'Create a new UserScore class and assign the properties.
        Dim userScore As UserScore
        userScore = New UserScore()
        userScore.Name = tokens(1)
        userScore.Score = Int32.Parse(tokens(0))
    
        'Add to the list of UserScore objects.
        scores.Add(userScore)
    Next
    
    'Sort them by descending order of score. To sort in the other
    'direction, remove the Descending keyword.
    scores = (From s In scores Order By s.Score Descending).ToList()
    

    You’ll need this class to hold the values. I have assumed that the Score will always be an integer – if it is something else then this field and the Int32.Parse call will need to be adjusted to suit.

    Class UserScore
        Property Name As String
        Property Score As Int32
    End Class
    

    Depending on how robust this needs to be, you may also want to check that the file opens successfully, the Int32.Parse call works (the TryParse method would be better in this case) and that the line.Split call returns an array with two values. Otherwise, that should do the trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.