|
-
Jan 15th, 2004, 12:41 AM
#1
Thread Starter
Lively Member
Reading from a text file [Resolved]
I use the following code to write individual lines into a text file:
Dim m_strTestFile As String = "c:\test.txt"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim writer As New IO.StreamWriter(m_strTestFile)
writer.Write(TextBox1.Text & vbCrLf)
writer.Write(TextBox2.Text & vbCrLf)
writer.Write(TextBox3.Text & vbCrLf)
writer.Write(TextBox4.Text & vbCrLf)
writer.Flush()
writer.Close()
End Sub
The test.text file looks like this with the text that has been typed in the boxes.
Text Box Line 1
Text Box Line 2
Text Box Line 3
Text Box Line 4
If say the boxes were reset and did not have text in them any longer, how can I use the IO.StreamReader to recall the individual lines back into the text boxes they were written in originally with another button click? Would it be easier to use an xml format and if so could someone give an example of both read and write to get me started in that direction?
Thanks in advance
Last edited by teamdad; Jun 13th, 2004 at 08:15 PM.
-
Jan 15th, 2004, 02:57 AM
#2
Sleep mode
A basic way to do it is this :
VB Code:
Private Sub readTxt(ByVal path As String)
Dim sr As New IO.StreamReader(path)
Me.textbox1.text = sr.ReadLine
Me.textbox2.text = sr.ReadLine
Me.textbox3.text = sr.ReadLine
Me.textbox4.text = sr.ReadLine
sr.Close()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|