|
-
Jun 10th, 2006, 08:09 PM
#1
[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?
-
Jun 10th, 2006, 08:22 PM
#2
Re: [2005] How to write richtextbox line by line to file
VB Code:
For Each str As String In rtf.Lines
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 10th, 2006, 11:04 PM
#3
Addicted Member
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,
=======================================
If I helped you, Kindly Rate my post. Thanks
-----------
PHENOM 
-
Jun 11th, 2006, 08:59 AM
#4
Re: [2005] How to write richtextbox line by line to file
oh, simple as that!
I was messing around with getlinefromchar etc. etc.
Thanks.
-
Jun 11th, 2006, 09:15 AM
#5
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?
-
Jun 11th, 2006, 09:26 AM
#6
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 11th, 2006, 11:06 AM
#7
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.
-
Jun 11th, 2006, 11:10 AM
#8
Addicted Member
Re: [RESOLVED] [2005] How to write richtextbox line by line to file
 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 i was working on it but you done it first 
Regards
=======================================
If I helped you, Kindly Rate my post. Thanks
-----------
PHENOM 
-
May 24th, 2007, 06:39 AM
#9
New Member
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
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
|