Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RichTextBox confusion!!!

Status
Not open for further replies.

emeryp

Programmer
Feb 2, 2003
25
US
Hi everyone,
I can use the RichTextBox.savefile and the RichTextBox.loadfile but the loadfile will not load the same file as the save file and I can't figure out how to copy the savefile to the loadfile for loading. Sounds stupid doesn't it? Can someone help?
 
This should be straightforward - show us some code!
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Here it is, I went back and looked and found that the real issue is appending to the file prior to loading it into the richtextbox:

Private Sub Command1_Click()
RichTextBox2.SaveFile "C:\VB
Projects\Test\RichTxtBox\InputFile.rtf", rtfRTF
End Sub

Private Sub Form_Load()
RichTextBox1.LoadFile "C:\VB Projects\Test\RichTxtBox\InputFile2.rtf", rtfRTF
Call Timer1_Timer
End Sub

Private Sub Timer1_Timer()
Dim InFile As String
Dim OutFile As String

DoEvents
InFile = "C:\VB Projects\Test\RichTxtBox\InputFile.rtf"
OutFile = "C:\VB Projects\Test\RichTxtBox\InputFile2.rtf"

FileCopy InFile, OutFile

'Now, the file is copied but it over writes the old file
'Cannot figure out how to append to the file so that the
'old text is not lost
RichTextBox1.LoadFile OutFile, rtfRTF

Timer1.Interval = 2001
End Sub
 
The loadfile and savefile methods are a good solution when you want to load or save the entire contents of a file. At times, however, you might want to append the contents of the control to an existing file or store multiple portions of text in the same file. In such cases you can use the TextRtf property with regular visual basic file commands and functions.

----Programming VB 6 by Francesco Balena Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Sorry but I'm having trouble seeing what you're trying to do.

There appears to be no appending or saving going on that's related to RichTextBox1.

It looks like you load InputFile2 into RTB1, then immediately overwrite InputFile2 with InputFile, then load the copied file straight back into the RTB1.

Have I missed something?
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Let me try again to append to a file and get back to both of you. John, the filecopy method was used because my append try didn't work. I will use the TextRTF property this time.
 
The following code does not append to the file. I wonder if the LoadFile method of the RTB is locking the file and not allowing the append to take place? Any ideas?:

Dim OutFile As String

Private Sub Command1_Click()
NewStr = RichTextBox2.TextRTF
Open OutFile For Append As #3
Write #3, NewStr
Close #3
End Sub

Private Sub Form_Load()
OutFile = "C:\VB Projects\Test\RichTxtBox\OutputFile.rtf"

RichTextBox1.LoadFile OutFile, rtfRTF
Call Timer1_Timer
End Sub

Private Sub Timer1_Timer()
DoEvents
RichTextBox1.LoadFile OutFile, rtfRTF
Timer1.Interval = 2001
End Sub
 
Can someone please check this code and tell me why it doesn't append to a file? See last message for code.
 

dim tmp as variant
open "c:\yourfile.rtf" for binary as #1
tmp = richtextbox1.textRTF: put #1 ,,tmp
tmp = richtextbox2.textRTF: put #1,,tmp
close #1
Robert Berman
Data Base consultant
Vulcan Software Services
thornmastr@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top