Results 1 to 9 of 9

Thread: [RESOLVED] [2005] How to write richtextbox line by line to file

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Resolved [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?

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [2005] How to write richtextbox line by line to file

    VB Code:
    1. 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

  3. #3
    Addicted Member phenom's Avatar
    Join Date
    Apr 2006
    Location
    UAE
    Posts
    233

    Re: [2005] How to write richtextbox line by line to file

    Hi Bulldog,

    use tis code:
    VB Code:
    1. Dim strWrite As New StreamWriter("c:\File001.txt")
    2.  For Each line As String In RichTextBox1.Lines
    3.         strWrite.WriteLine(line)
    4.  Next
    5.  strWrite.Close()
    6.  Messagebox.Show("DONE")
    Hope this helps...

    Regards,
    =======================================
    If I helped you, Kindly Rate my post. Thanks
    -----------
    PHENOM

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] How to write richtextbox line by line to file

    oh, simple as that!

    I was messing around with getlinefromchar etc. etc.

    Thanks.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    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:
    1. Dim w As New System.IO.StreamWriter(TargetFile, False, FileNameEncoding)
    2.                 For Each str As String In SearchText.Lines
    3.                     w.Writeline(str)
    4.                 Next
    5.                 w.Close()

    I get the same problem if I use w.Write(str + vbCrLf)

    What am I doing wrong?

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [RESOLVED] [2005] How to write richtextbox line by line to file

    You really are a VB6 Programmer!!
    You should use:
    VB Code:
    1. w.WriteLine(str)
    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

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [RESOLVED] [2005] How to write richtextbox line by line to file

    This is what I ended up with...

    VB Code:
    1. Dim w As New System.IO.StreamWriter(TargetFile, False, FileNameEncoding)
    2.                 For i As Integer = 0 To SearchText.Lines.Length - 2
    3.                     w.WriteLine(SearchText.Lines(i))
    4.                 Next
    5.                 w.Write(SearchText.Lines(SearchText.Lines.Length - 1))
    6.                 w.Close()

    Which avoids the extra line added by the streamwriter.

  8. #8
    Addicted Member phenom's Avatar
    Join Date
    Apr 2006
    Location
    UAE
    Posts
    233

    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:
    1. Dim w As New System.IO.StreamWriter(TargetFile, False, FileNameEncoding)
    2.                 For i As Integer = 0 To SearchText.Lines.Length - 2
    3.                     w.WriteLine(SearchText.Lines(i))
    4.                 Next
    5.                 w.Write(SearchText.Lines(SearchText.Lines.Length - 1))
    6.                 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

  9. #9
    New Member
    Join Date
    Jun 2005
    Posts
    1

    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
  •  



Click Here to Expand Forum to Full Width