I know you guys are normally not usually willing to mess with stuff like this because it is so beginner, but i'm in need of major help. I have already created the code for the game it self, and it works perfectly fine. I now want to know how to record the results of each game to a text file. Here is my current code. I know I have to create a streamwriter and reader to open, but am a bit lost. Is it possible with my current code or do I need to start over completely? Thanks in advance!

Public Class Form1


    Private Sub rock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rock.Click
        Dim randomGenerator As New Random
        Dim computerChoice As Integer

        player.image = rock.Image

        computerChoice = randomGenerator.Next(1, 4)
        If computerChoice = 1 Then
            computer.image = rock.Image
            winner.Text = "Tie"
        ElseIf computerChoice = 2 Then
            computer.image = paper.Image
            winner.Text = "Computer wins because paper covers rock."
        ElseIf computerChoice = 3 Then
            computer.Image = scissors.Image
            winner.Text = "Player wins because rock shatters scissors."

        End If


    End Sub


    Private Sub paper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles paper.Click
        Dim randomGenerator As New Random
        Dim computerChoice As Integer

        player.Image = paper.Image

        computerChoice = randomGenerator.Next(1, 4)
        If computerChoice = 1 Then
            computer.Image = rock.Image
            winner.Text = "Player wins because paper covers rock."
        ElseIf computerChoice = 2 Then
            computer.Image = paper.Image
            winner.Text = "Tie."
        ElseIf computerChoice = 3 Then
            computer.Image = scissors.Image
            winner.Text = "Computer wins because scissors cuts paper."

        End If

    End Sub

    Private Sub scissors_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles scissors.Click

        Dim randomGenerator As New Random
        Dim computerChoice As Integer

        player.Image = scissors.Image

        computerChoice = randomGenerator.Next(1, 4)
        If computerChoice = 1 Then
            computer.Image = rock.Image
            winner.Text = "Computer wins because rock shatters scissors."
        ElseIf computerChoice = 2 Then
            computer.Image = paper.Image
            winner.Text = "Player wins because scissors cuts paper."
        ElseIf computerChoice = 3 Then
            computer.Image = scissors.Image
            winner.Text = "Tie."

        End If
    End Sub
End Class

Think you are posting in wrong area. This area is about C++

Moved to VB.NET forum.

I'm assuming that "winner" is a label. If so, then I suggest you add a TextChanged handler for that control and put the file save code there. That way, whenever you post the status of the next game the results will automatically get recorded.

The easiest way would be to just append to a results file.

Private Sub winner_TextChanged(sender As System.Object, e As System.EventArgs) Handles winner.TextChanged
    Dim sw As System.IO.StreamWriter = System.IO.File.AppendText("d:\temp\results.txt")
    sw.WriteLine(winner.Text)
    sw.Close()
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.