|
-
Apr 12th, 2011, 03:58 AM
#1
Thread Starter
Addicted Member
[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 !
-
Apr 12th, 2011, 07:33 AM
#2
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
-
Apr 12th, 2011, 08:51 AM
#3
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.
-
Apr 12th, 2011, 04:22 PM
#4
Thread Starter
Addicted Member
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.....
-
Apr 12th, 2011, 04:58 PM
#5
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
-
Apr 12th, 2011, 10:27 PM
#6
Thread Starter
Addicted Member
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.
-
Apr 12th, 2011, 10:35 PM
#7
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|