Results 1 to 7 of 7

Thread: [RESOLVED] RichTextBox save edits

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    Resolved [RESOLVED] RichTextBox save edits

    with the RichTextBox, I am reading in text from a file with .LoadFile
    and saving it again with .Savefile
    2 problems:
    -I want to programmatically add lines of text to the beginning of the RTBox
    How do I insert at the beginning?
    -I want to also let the user add text (anywhere) and save all the text.
    user text can be added on screen OK, but when I save/load the file the user text is missing !

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: RichTextBox save edits

    Insert at the beginning:
    Code:
    Dim InsText As String
    InsText = "Line 1 " & vbNewLine & "Line 2" ' or whatever
    RTB1.Text = InsText & RTB1.Text
    Don't understand your 2nd point

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: RichTextBox save edits

    You can also set SelStart and SelLength to 0, then set SelText to the text to be inserted at the beginning. Much faster and cheaper than dragging out all of the text then storing it all back in there.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    Re: RichTextBox save edits

    for problem #2:
    -I want to also let the user add text (anywhere) and save all the text.
    user text can be added on screen OK, but when I save/load the file the user text is missing !


    The user can type text into the RTBox (along with computer generated text)
    but if I save the RTB text to a file & reload it, the user text is missing.....

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: RichTextBox save edits

    what is the code you are using that is not working correctly?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    Re: RichTextBox save edits

    This is what I am doing:
    Code:
           RTBlog.LoadFile  nameoffile, rtfRTF
           RTBlog.SelLenght =0         
           RTBlog.SelStart = 0
           RTBlog.SelText =  "text to add by computer" & VBNewLine
    and later....
    Code:
           RTBlog.SaveFile   nameoffile, rtfRTF
    When I later reload from the file with .LoadFile again, any text entered into the RTBox by the user is lost.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    new zealand (kiwi)!
    Posts
    202

    Re: RichTextBox save edits

    Found my problem!
    I wasn't saving the RTB data to file on form exit....
    everything working great. thanks for help

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