writing to a text document
Moderator: Moderators
writing to a text document
im making a tictactoe game in vb.net, and im going to use a text document to store some values (for network play), but i don't know how to do it.. the only way i know how is to put stuff into a rich text document, then save from there.. is there a more official way to do it? and how do you read a specific line..
-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
'You can replace strWorkingDirectory & "Schema.ini" with the
'name of you file to be written
Imports System.IO
Dim sw As New System.IO.StreamWriter(strWorkingDirectory & "Schema.ini")
sw.WriteLine(strSomeString)'This written string could be something
'you read in with a streamreader...
sw.Close()
sw.Dispose() 'can't really remember if you need the dispose, but give it try 1st
'Please let me know if this isn't clear or what you are looking for
'name of you file to be written
Imports System.IO
Dim sw As New System.IO.StreamWriter(strWorkingDirectory & "Schema.ini")
sw.WriteLine(strSomeString)'This written string could be something
'you read in with a streamreader...
sw.Close()
sw.Dispose() 'can't really remember if you need the dispose, but give it try 1st
'Please let me know if this isn't clear or what you are looking for
-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
So if I get you right you're trying to write the contents of a text box or somethign, right.
can't you just put the contexts of the text box into a string
and then write that particular string instead of strSomeString.
Also you probably gonna be a bit more specific about something not working I think. Like what particular error are you getting? Thanks.
Jeff
can't you just put the contexts of the text box into a string
and then write that particular string instead of strSomeString.
Also you probably gonna be a bit more specific about something not working I think. Like what particular error are you getting? Thanks.
Jeff
-
jeffslot
- Portablizer Extraordinaire
- Posts: 853
- Joined: Wed Jun 01, 2005 6:26 am
- Location: PA
- Contact:
Hi, I just tested this code in vb.net 2.0 successfully, let me know if it helps you.
Jeff
Jeff
Code: Select all
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sw As New StreamWriter("C:\TestOutput.txt", False)
Dim sb As New StringBuilder
sb.Append(TextBox1.Text)
sw.WriteLine(sb)
sw.Close()
sw.Dispose()
sb = Nothing
End Sub
End ClassSorry about that. Well, what the idea I had was, is to do this:
Game of tic-tac-toe
player 1 = 1s
player 2 = 2s (not for the visuals, just for variables sake, like when you click the box, that spot becomes a 1 or 2)
Basically, every .5 second or so, check and update the document (which is somewhere both PCs can access).
So heres the layout for the document
(the numbers refer to the line numbers)
1.spot1
2.spot2
3.spot3
4.spot4
5.spot5
6.spot6
7.spot7
8.spot8
9.spot9
10.TurnNumber
11.Player1Name
12.Player2Name
13.Player1Wins
14.Player2Wins
thats a rough sketch
now, what i want to do, is each time i say, click spot 2 as player 1 (1st row, second column) it would write a 1 in line 2. Then after about .3 of a second, both computers would read the document, and since line 2 changed, it would render the "X" or "O" on spot 2 in the form (so it checks,writes, then reads,then updates, in a continous loop every .3 seconds or so. Does that make sense?
Game of tic-tac-toe
player 1 = 1s
player 2 = 2s (not for the visuals, just for variables sake, like when you click the box, that spot becomes a 1 or 2)
Basically, every .5 second or so, check and update the document (which is somewhere both PCs can access).
So heres the layout for the document
(the numbers refer to the line numbers)
1.spot1
2.spot2
3.spot3
4.spot4
5.spot5
6.spot6
7.spot7
8.spot8
9.spot9
10.TurnNumber
11.Player1Name
12.Player2Name
13.Player1Wins
14.Player2Wins
thats a rough sketch
now, what i want to do, is each time i say, click spot 2 as player 1 (1st row, second column) it would write a 1 in line 2. Then after about .3 of a second, both computers would read the document, and since line 2 changed, it would render the "X" or "O" on spot 2 in the form (so it checks,writes, then reads,then updates, in a continous loop every .3 seconds or so. Does that make sense?
