Save score from a game

Hokta

New member
Joined
Oct 24, 2012
Messages
1
Programming Experience
Beginner
Hello,

I'm a student and I have to create a MasterMind game in VB.net language,
everything it's ok except one thing : I don't know how to save score from my MasterMind in a .txt file

Public Sub SaveScore()


FileOpen(1, "score.txt", OpenMode.Append)
For i = 1 To 20
PrintLine(1, TabScores(i))
Next


FileClose(1)

I've find how to load it when I start a new game but when I have to save nothing append
My score.txt file is located in mastermind>Bin>Debug

Thank you !
 
Hi,

I have quickly tried your code and there is nothing wrong with your code to output to a file. I would therefore suggest that your TabScores array is empty at the time you write to your output file. In addition to this you must remember that an array is indexed from zero and therefore to get all the elements of your array you should use:-

For i = 0 to TabScores.Count-1

You may also want to look using a StreamWriter and StreamReader class to read and write your files instead of the using the old VB6 techniques.

Cheers,

Ian
 
Back
Top