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!

trying to open a file for a rich textbox.

Status
Not open for further replies.

ebbs

Programmer
Nov 10, 2001
2
US
Hi,
I am trying to use a rich textbox and populate it by opening a file and having the contents copy to the rich textbox. Of course I also need to write back out to the file when I am done. These files would be under MyDocuments or something like that. Nothing complicated.
I have looked on the microsoft site and found the OpenFileDialog references. BUT, I can't seem to make sense of it. I thought that it might be like a commondialog1 control, but I can't find it in the components listing.
I printed out the microsoft documentation and tried to type in exactly what they had.... NO LUCK. That's what made me thing that it must be a component/control... But I can't find it.

Thanks
Ebbs
 
Use the CommonDialog to allow the user select the Filename then put the filname in the Filename property to load up the RTF.
rtf.Filename = strFileName ' Text or RTF to load
Use rtf.SaveFile method to save the file. Compare Code (Text)
Generate Sort in VB or VBScript
 
The exactly name is :

Microsoft Common Dialog control 6.0 (SP3)

Please let me know if you can't find it.
It's an OCX you can download.

Best regards.

You're never to old to learn but the older i get the more i forget.

Best regards.
 
Hi,
Originally, I wrote the program using a regular textBox. I used the commdialog control to get the file name and I used "Open strFileName For Output As #1" to open the file. I had everything working, however, it did not handle Word documents (rich text). So I wanted to use the rich TextBox.
But then it would not load the data properly into the rich text box either. SO, I thought that there must be way more to it. I went to microsoft.com and found OpenFileDialog and RichTextBox.LoadFile documentation.
I found the load statement "richtextbox1.loadfile(openfile1.filename, richtextbox1streamtype.plaintext);"
So then I assumed that I needed an openfile control. That's when I found the openfiledialog documentation.
One of the statments "Dim openFileDialog1 As New" gets a compile error as soon as I leave the line.
SOOO, basically, I'm lost.

PLEASE NOTE: I am a biginner at VB. I am just learning.
The statement "rtf.Filename = strFileName
' Text or RTF to load" is too little
information for me.

Thanks
EBBS
 
Ok...if your rich textbox is called RichTextBox1 then this will load the file "c:\test.rtf" into your rich textbox:

Code:
RichTextBox1.LoadFile "c:\test.rtf"

The ability to save into and load from files already exists in the richtextbox control.

Now, if you want the user to be able to specify the location of the file with the common dialog control, you can add it to your form, use .ShowSave or .ShowOpen (whichever is applicable), set a variable equal to .FileName (of your common dialog control) and then pass that variable into the richtextbox's .LoadFile method, like thus:

CD = common dialog control
RTF = richtextbox control

Code:
Dim rtfFileLocation
CD.ShowOpen
rtfFileLocation = CD.FileName
RTF.LoadFile rtfFileLocation

::whew:: I hope that wasn't overly convoluted.

Hope this helps,
J
 
You are out of luck if you are trying to Load a Word Document i.e. DOC file. The file MUST be a plain text or RTF (Rich Text Format) file. A .DOC file is neither of these although WOrd can be instreucted to store a document as in RTF rather than DOC. Compare Code (Text)
Generate Sort in VB or VBScript
 
so it would be possible to create a Word-application object, open the .DOC file and save it like a .RTF file without ever showign the Word-windows ... than the RTF file can be opened and modified from within the Richtextbox

Bas Schouten
System Development & Webdesign
CBIS BV Holland
logo.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top