teamdad Posted January 15, 2004 Posted January 15, 2004 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 Quote
Leaders Iceplug Posted January 15, 2004 Leaders Posted January 15, 2004 Seems like you should only have to create a System.IO.StreamReader and then TextBox1.Text = SR.ReadLine() TextBox2.Text = SR.ReadLine() ... :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Administrators PlausiblyDamp Posted January 15, 2004 Administrators Posted January 15, 2004 also you could have used writer.WriteLine(.....) instead of appending the linefeed yourself - this would aid portability to other .Net languages which may not support the VB constants. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.