| | |
Cant readline in text file.... URGENT help~
Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Mar 2006
Posts: 3
Reputation:
Solved Threads: 0
i'm doing a game function which able to save and load game function, i want to do it in a simple way cause only a few information need to collect. :cry:
Here is the save method i use which able to write things into the .txt file which work correctly that the txt have the information wat it written.
-----Save (write to text file)
If respond = MsgBoxResult.Yes Then
strmw.Write(vbCrLf)
'loop all the player status
strmw.WriteLine(String.Format((NumPlayer.Text)))
For x = 1 To Val(NumPlayer.Text)
' write detail in the record
strmw.WriteLine(String.Format((x)))
strmw.WriteLine(String.Format(wpname(x).Text))
strmw.WriteLine(String.Format(wPP(x).Text))
strmw.WriteLine(String.Format(wcounter(x).Text))
savegamesound()
Next
strmw.WriteLine(String.Format(PTurn.Text))
strmw.Close()
MsgBox("Game Saved", MsgBoxStyle.OKOnly)
Else : Exit Sub
End If
--------------- LOad function (read from .txt... i think problem were be here anyone know wat happen?? sory to said that i cant use the "for loop" cause i cant use too much array where my system cannot handle with it so used in the old method. i found out that is only read the first line of my entire text file.. and the other value was empty.. like didnt access to it...
If respond = MsgBoxResult.Yes Then
strmw = File.OpenText(filePath)
'loop the player status according to the "num" value
num = strmw.ReadLine()
If num = "1" Then
game.Pname1.Text = strmw.ReadLine()
game.PP1.Text = strmw.ReadLine()
game.counter1.Text = strmw.ReadLine()
game.PTurn.Text = strmw.ReadLine() 'get whos turn
ElseIf num = "2" Then
game.Pname1.Text = strmw.ReadLine()
game.PP1.Text = strmw.ReadLine()
game.counter1.Text = strmw.ReadLine()
game.Pname2.Text = strmw.ReadLine()
game.PP2.Text = strmw.ReadLine()
game.counter2.Text = strmw.ReadLine()
game.PTurn.Text = strmw.ReadLine() 'get whos turn
ElseIf num = "3" Then
......
ElseIf num = "4" Then
......
End If
strmw.Close()
MsgBox("Loading sucess", MsgBoxStyle.OKOnly)
game.Show()
Me.Hide()
Else : Exit Sub
End If
Here is the save method i use which able to write things into the .txt file which work correctly that the txt have the information wat it written.
-----Save (write to text file)
If respond = MsgBoxResult.Yes Then
strmw.Write(vbCrLf)
'loop all the player status
strmw.WriteLine(String.Format((NumPlayer.Text)))
For x = 1 To Val(NumPlayer.Text)
' write detail in the record
strmw.WriteLine(String.Format((x)))
strmw.WriteLine(String.Format(wpname(x).Text))
strmw.WriteLine(String.Format(wPP(x).Text))
strmw.WriteLine(String.Format(wcounter(x).Text))
savegamesound()
Next
strmw.WriteLine(String.Format(PTurn.Text))
strmw.Close()
MsgBox("Game Saved", MsgBoxStyle.OKOnly)
Else : Exit Sub
End If
--------------- LOad function (read from .txt... i think problem were be here anyone know wat happen?? sory to said that i cant use the "for loop" cause i cant use too much array where my system cannot handle with it so used in the old method. i found out that is only read the first line of my entire text file.. and the other value was empty.. like didnt access to it...
If respond = MsgBoxResult.Yes Then
strmw = File.OpenText(filePath)
'loop the player status according to the "num" value
num = strmw.ReadLine()
If num = "1" Then
game.Pname1.Text = strmw.ReadLine()
game.PP1.Text = strmw.ReadLine()
game.counter1.Text = strmw.ReadLine()
game.PTurn.Text = strmw.ReadLine() 'get whos turn
ElseIf num = "2" Then
game.Pname1.Text = strmw.ReadLine()
game.PP1.Text = strmw.ReadLine()
game.counter1.Text = strmw.ReadLine()
game.Pname2.Text = strmw.ReadLine()
game.PP2.Text = strmw.ReadLine()
game.counter2.Text = strmw.ReadLine()
game.PTurn.Text = strmw.ReadLine() 'get whos turn
ElseIf num = "3" Then
......
ElseIf num = "4" Then
......
End If
strmw.Close()
MsgBox("Loading sucess", MsgBoxStyle.OKOnly)
game.Show()
Me.Hide()
Else : Exit Sub
End If
Hi
Are you having problem when you write to the file or when you read the file?
how did you define "strmw"? is it defined as a StreamWriter?
I see that you are reding with the same variable (StreamWriter). Try to declare a varible type StreamReader to read from the file and another one type StreamWriter to write to the file.
Also check this website, they exlplain in detail how to perform these two actions.
http://www.builderau.com.au/program/...644,20267367,0
Hope it helps
Are you having problem when you write to the file or when you read the file?
how did you define "strmw"? is it defined as a StreamWriter?
I see that you are reding with the same variable (StreamWriter). Try to declare a varible type StreamReader to read from the file and another one type StreamWriter to write to the file.
Also check this website, they exlplain in detail how to perform these two actions.
http://www.builderau.com.au/program/...644,20267367,0
Hope it helps
•
•
Join Date: Mar 2006
Posts: 3
Reputation:
Solved Threads: 0
i define it as Dim strmw As StreamReader,
i having problem when i read the txt line. is didnt get the value form the txt.file.... not sure wat happen...
i having problem when i read the txt line. is didnt get the value form the txt.file.... not sure wat happen...
•
•
•
•
Originally Posted by williamrojas78
Hi
Are you having problem when you write to the file or when you read the file?
how did you define "strmw"? is it defined as a StreamWriter?
I see that you are reding with the same variable (StreamWriter). Try to declare a varible type StreamReader to read from the file and another one type StreamWriter to write to the file.
Also check this website, they exlplain in detail how to perform these two actions.
http://www.builderau.com.au/program/...644,20267367,0
Hope it helps
•
•
Join Date: Jun 2008
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
i'm doing a game function which able to save and load game function, i want to do it in a simple way cause only a few information need to collect. :cry:
Here is the save method i use which able to write things into the .txt file which work correctly that the txt have the information wat it written.
-----Save (write to text file)
If respond = MsgBoxResult.Yes Then
strmw.Write(vbCrLf)
'loop all the player status
strmw.WriteLine(String.Format((NumPlayer.Text)))
For x = 1 To Val(NumPlayer.Text)
' write detail in the record
strmw.WriteLine(String.Format((x)))
strmw.WriteLine(String.Format(wpname(x).Text))
strmw.WriteLine(String.Format(wPP(x).Text))
strmw.WriteLine(String.Format(wcounter(x).Text))
savegamesound()
Next
strmw.WriteLine(String.Format(PTurn.Text))
strmw.Close()
MsgBox("Game Saved", MsgBoxStyle.OKOnly)
Else : Exit Sub
End If
--------------- LOad function (read from .txt... i think problem were be here anyone know wat happen?? sory to said that i cant use the "for loop" cause i cant use too much array where my system cannot handle with it so used in the old method. i found out that is only read the first line of my entire text file.. and the other value was empty.. like didnt access to it...
If respond = MsgBoxResult.Yes Then
strmw = File.OpenText(filePath)
'loop the player status according to the "num" value
num = strmw.ReadLine()
If num = "1" Then
game.Pname1.Text = strmw.ReadLine()
game.PP1.Text = strmw.ReadLine()
game.counter1.Text = strmw.ReadLine()
game.PTurn.Text = strmw.ReadLine() 'get whos turn
ElseIf num = "2" Then
game.Pname1.Text = strmw.ReadLine()
game.PP1.Text = strmw.ReadLine()
game.counter1.Text = strmw.ReadLine()
game.Pname2.Text = strmw.ReadLine()
game.PP2.Text = strmw.ReadLine()
game.counter2.Text = strmw.ReadLine()
game.PTurn.Text = strmw.ReadLine() 'get whos turn
ElseIf num = "3" Then
......
ElseIf num = "4" Then
......
End If
strmw.Close()
MsgBox("Loading sucess", MsgBoxStyle.OKOnly)
game.Show()
Me.Hide()
Else : Exit Sub
End If
Why dont you just use an Ini file that would be the idea then you can maybe encrypt it so people playing the Game couldnt cheat
like
SaveName=My Saved Game
MapLevel=Level2
Health=50
somthing like that would work geat i think
i have a ini Handler you might be able to use and its real simple.
![]() |
Similar Threads
- connect to text file database (Visual Basic 4 / 5 / 6)
- text file manipulations (Visual Basic 4 / 5 / 6)
- Trying to obtain text from a file. (C#)
- Binary Search on a text file (Java)
- using a "for" loop to read a text file (VB.NET)
- Read and write to an ASCII Text file (Java)
Other Threads in the VB.NET Forum
- Previous Thread: VB.NET 2008, datagrid query
- Next Thread: how to blink the text of button
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic binary bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





