[RESOLVED] [2005] How to write richtextbox line by line to file
I want to write the contents of a richtextbox one line at a time to a file (I need to end each line with a crlf), how do I loop through the richtextbox lines?
Re: [2005] How to write richtextbox line by line to file
VB Code:
For Each str As String In rtf.Lines
Re: [2005] How to write richtextbox line by line to file
Hi Bulldog,
use tis code:
VB Code:
Dim strWrite As New StreamWriter("c:\File001.txt")
For Each line As String In RichTextBox1.Lines
strWrite.WriteLine(line)
Next
strWrite.Close()
Messagebox.Show("DONE")
Hope this helps...
Regards,
Re: [2005] How to write richtextbox line by line to file
oh, simple as that!
I was messing around with getlinefromchar etc. etc.
Thanks.
Re: [RESOLVED] [2005] How to write richtextbox line by line to file
Actually, the code doesnt do quite what I expect. It always adds one extra line to the file.
This is my code;
VB Code:
Dim w As New System.IO.StreamWriter(TargetFile, False, FileNameEncoding)
For Each str As String In SearchText.Lines
w.Writeline(str)
Next
w.Close()
I get the same problem if I use w.Write(str + vbCrLf)
What am I doing wrong?
Re: [RESOLVED] [2005] How to write richtextbox line by line to file
You really are a VB6 Programmer!!
You should use: But that won't fix it, I guess it's a Microsoft bug of something
Re: [RESOLVED] [2005] How to write richtextbox line by line to file
This is what I ended up with...
VB Code:
Dim w As New System.IO.StreamWriter(TargetFile, False, FileNameEncoding)
For i As Integer = 0 To SearchText.Lines.Length - 2
w.WriteLine(SearchText.Lines(i))
Next
w.Write(SearchText.Lines(SearchText.Lines.Length - 1))
w.Close()
Which avoids the extra line added by the streamwriter.
Re: [RESOLVED] [2005] How to write richtextbox line by line to file
Quote:
Originally Posted by Bulldog
This is what I ended up with...
VB Code:
Dim w As New System.IO.StreamWriter(TargetFile, False, FileNameEncoding)
For i As Integer = 0 To SearchText.Lines.Length - 2
w.WriteLine(SearchText.Lines(i))
Next
w.Write(SearchText.Lines(SearchText.Lines.Length - 1))
w.Close()
Which avoids the extra line added by the streamwriter.
well done :thumb: i was working on it but you done it first ;) :bigyello:
Regards
Re: [RESOLVED] [2005] How to write richtextbox line by line to file
hello my code is as below...in vb 6.0
dim line as string
For Each line In RichTextBox1.Lines
msgbox line
next
but i am getting error like "Method or Datamember not found" in
For Each line In RichTextBox1.Lines
Kinjal