CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2012
    Posts
    5

    How to remember data after the program is closed?

    I'm making a high score list, so I need to store the names of players that achieved the highest score.

    Basicaly, you would enter your name (ok, this is easy), your name is saved, you exit the program, and when you run the program next time, your name will still be on the list?

    How can I do this?

  2. #2
    Join Date
    Jan 2007
    Posts
    491

    Re: How to remember data after the program is closed?

    There are lots of ways to save data:
    -using Settings
    -write the data to files, and then read it
    -save the data in a Database

    In your case (highscore), writing to top scores to a file (either a simple txt file or an xml file) seems like the best option.
    Here's a quick guide that teaches how to read and write to files:
    http://www.csharp-station.com/HowTo/...eTextFile.aspx

  3. #3
    Join Date
    Apr 2012
    Posts
    5

    Re: How to remember data after the program is closed?

    Thanks for the fast reply.

    So ok, I've created the txt file within the project, and I can't open it with the stream reader command cause I can't find the right path to the file. Here is a pic of it's location.

    My question is:

    StreamReader sr = new StreamReader(WHAT SHOULD I PUT HERE);
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2007
    Posts
    491

    Re: How to remember data after the program is closed?

    You don't need to create the file in advance, just create the file in the code.
    In fact, you don't need to do anything different, because the StreamWriter class creates an empty file if the file (in the path you passed to it as a constructor argument) doesn't exist.

  5. #5
    Join Date
    Apr 2012
    Posts
    5

    Re: How to remember data after the program is closed?

    Ok, thanks!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured