Results 1 to 13 of 13

Thread: [RESOLVED] read content in richtexbox line by line and save in c:\mydir\test.txt

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Resolved [RESOLVED] read content in richtexbox line by line and save in c:\mydir\test.txt

    read content in richtexbox line by line and save in c:\mydir\test.txt
    ????

    Instead other way are welcome.

    in effect i need to print all lines from richtexbox and insert in txt.

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Code:
        Dim Lines() As String
        Dim c As Long
        
        Lines = Split(RichTextBox.Text, vbCrLf)
        For c = 0 To UBound(Lines)
            Debug.Print Lines(c)
        Next

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by Eduardo- View Post
    Code:
        Dim Lines() As String
        Dim c As Long
        
        Lines = Split(RichTextBox.Text, vbCrLf)
        For c = 0 To UBound(Lines)
            Debug.Print Lines(c)
        Next
    work! tks.

    But why to the end of txt file have a blank line? I dont need!

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by luca90 View Post
    work! tks.

    But why to the end of txt file have a blank line? I dont need!
    It must be that the text has a carriage return at the end, aka a blank line.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by Eduardo- View Post
    It must be that the text has a carriage return at the end, aka a blank line.
    OK
    but possible to not have?

  6. #6
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by luca90 View Post
    OK
    but possible to not have?
    You could always just check if the last line is a blank line and if so then don't write it out.

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Why write it line by line? Why not just write it all at once?

    Code:
    Print #1, Richtextbox1.Text;
    the ; on the end prevents the print statement from adding a crlf at the end

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by PlausiblyDamp View Post
    You could always just check if the last line is a blank line and if so then don't write it out.
    ????

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by luca90 View Post
    OK
    but possible to not have?
    Ok:

    Code:
        Dim Lines() As String
        Dim c As Long
        
        Lines = Split(RichTextBox.Text, vbCrLf)
        c = UBound(Lines)
        Do While Lines(c) = ""
            c = c - 1
        Loop
        ReDim Preserve Lines(c)
        For c = 0 To UBound(Lines)
            Debug.Print Lines(c)
        Next

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Code:
    RichTextBox.SaveFile "saved.txt", rtfText
    Bam! All done.

  11. #11
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by dilettante View Post
    Code:
    RichTextBox.SaveFile "saved.txt", rtfText
    Bam! All done.
    Doesn't that save it in rtf format?

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: read content in richtexbox line by line and save in c:\mydir\test.txt

    Quote Originally Posted by DataMiser View Post
    Doesn't that save it in rtf format?
    No, explicitly asking for text format doesn't save in RTF format.

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: [RESOLVED] read content in richtexbox line by line and save in c:\mydir\test.txt

    Been a long time since I used it, the rtfText on the end made me think it was calling for rtf format.

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