Altering a resource text file

dumdumsareyum

New member
Joined
Dec 9, 2008
Messages
4
Programming Experience
1-3
I have an embedded resource text file that I can access to read but cannot figure out how to alter the text file during runtime. Here is my code to read from the file:

VB.NET:
 Public Sub LoadTopScores()
        'Load top scores
        Try
            Dim _textStreamReader As StreamReader
            Dim _assembly As [Assembly]
            Dim scores As String = "HighScores.txt"

            _assembly = [Assembly].GetExecutingAssembly()
            _textStreamReader = New StreamReader(_assembly.GetManifestResourceStream("WheelofFortune." + scores))

            For intCount As Integer = 0 To 9
                strTopPlayers(intCount) = _textStreamReader.ReadLine()
                intTopScores(intCount) = CInt(_textStreamReader.ReadLine())
            Next intCount

        Catch ex As Exception
            MessageBox.Show("Resource not found!")
        End Try

Here is what I am trying to do to write to the file, basically just trying to substitute writing for reading, but it's not working:

VB.NET:
 Try

            Dim _assembly As [Assembly]
            Dim scores As String = "HighScores.txt"
            Dim _textStreamWriter As StreamWriter

            _assembly = [Assembly].GetExecutingAssembly()
            _textStreamWriter = New StreamWriter(_assembly.GetManifestResourceStream("WheelofFortune." + scores))

            _textStreamWriter = File.CreateText(scores)

            For intCount As Integer = 0 To 9
                _textStreamWriter.WriteLine(strTopPlayers(intCount).ToString)
                _textStreamWriter.WriteLine(intTopScores(intCount).ToString)
            Next intCount

            _textStreamWriter.Close()

        Catch ex As Exception
            MessageBox.Show("Resource not found!")
        End Try

Help please?
 
Embedded resources are compiled into the exe and is readonly. You have to use file system for writable data storage. It is also possible with a user setting of type string in Application settings.
 
Muchas gracias.....I was afraid of that....this is for one of my VB final projects and we hadn't really learned about resource files yet, but after having my hubby play my other game and say "hey I hacked your high scores" when he changed my text file, I thought I would try it and have a super bad-ass project. Maybe next time :)
 
Back
Top