decrypt Posted April 3, 2004 Posted April 3, 2004 How could i read and write to a text file? ie. read it, edit the information manually, save it... Quote
*Experts* mutant Posted April 3, 2004 *Experts* Posted April 3, 2004 Look into thoses two classes: System.IO.StreamReader and System.IO.StreamWriter. Quote
PureSc0pe Posted April 3, 2004 Posted April 3, 2004 I had asked about this before... Click Here Quote It's not impossible, it's Inevitable.
decrypt Posted April 3, 2004 Author Posted April 3, 2004 How would i get this: Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim line As String = "" Dim SR As New IO.StreamReader(TextBox2.Text) Dim SB As System.Text.StringBuilder = New System.Text.StringBuilder Do line = SR.ReadLine If line <> TextBox4.Text Then SB.Append(line) SB.Append(System.Environment.NewLine) End If Loop Until line = "" SR.Close() Dim SW As New IO.StreamWriter(TextBox2.Text, False) SW.Write(SB.ToString()) SW.Close() End Sub To read every line? Also how would i read this from a file? (.txt file) I want it to read the whole file and display it in a textbox... (like what notepad does) Quote
decrypt Posted April 3, 2004 Author Posted April 3, 2004 this doesn't seem to be working: Dim oFile As System.IO.File Dim oRead As System.IO.StreamReader oRead = oFile.OpenText("D:\Image.txt") Dim EntireFile As String EntireFile = oRead.ReadToEnd() TextBox2.Text = EntireFile Quote
Administrators PlausiblyDamp Posted April 3, 2004 Administrators Posted April 3, 2004 Any hints as to what you mean by 'doesn't seem to be working'? Does it give any errors? Does the file exist? Is anything else using the file? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
decrypt Posted April 4, 2004 Author Posted April 4, 2004 The problem is is that it doesn't read all the lines :/ Quote
keitsi Posted April 4, 2004 Posted April 4, 2004 dim sr as streamreader = new streamreader("c:\test.txt") do until sr.peek =< 0 debug.writeline sr.readline loop if you want to whole file at once you could try binary mode Quote BS - Beer Specialist
decrypt Posted April 5, 2004 Author Posted April 5, 2004 i've been wondering this for a while... what does debug.writeline do? Is there anyway to change the debug.writeline to something that with textbox1.text... Quote
decrypt Posted April 5, 2004 Author Posted April 5, 2004 (edited) Yay, i got it working, i just mixed the two together: Dim line As String = "" Dim sr As System.IO.StreamReader = New System.IO.StreamReader("C:/text.txt") Do line = sr.ReadLine If line <> TextBox2.Text Then TextBox2.AppendText(line) TextBox2.AppendText(System.Environment.NewLine) End If Loop Until line = "" Do you know how i could do this now by writing to a file? Edited April 5, 2004 by decrypt Quote
Leaders Iceplug Posted April 6, 2004 Leaders Posted April 6, 2004 How could you do what by writing to a file? To write to a file, use StreamWriter instead of StreamReader. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
CattleRustler Posted April 6, 2004 Posted April 6, 2004 debug.writeline() writes a string to the Output Window followed with a carriage return/line feed it's used for debugging your app during runtime. Quote mod2software Home of the VB.NET Class Builder Utility - Demo and Full versions available now!
decrypt Posted April 12, 2004 Author Posted April 12, 2004 How could you do what by writing to a file? To write to a file, use StreamWriter instead of StreamReader. :) i just want to know how you can write text to a text file, simply... Quote
PureSc0pe Posted April 13, 2004 Posted April 13, 2004 i just want to know how you can write text to a text file' date=' simply...[/quote'] Dim SW As New IO.StreamWriter("where to write") SW.WriteLine("what to write") 'example: TextBox1.Text SW.Close() Quote It's not impossible, it's Inevitable.
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.