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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help! i'm a VB newbie, and i want to make a simple RTF editor

Status
Not open for further replies.

computerwizz

Programmer
Dec 2, 2000
2
US
hey everyone, thanks in advance.

I am trying to make a simple RTF editor, becuse i dont like the functionality of wordpad, but anyway.

on my form, i have placed an RTF box, and called if rtf1. everying else about the editor is fine, but i can't figure out how to save the rtf to a .rtf file. i had some code that i thought would work, but it doesnt. so can anyone tell me the code for saving the text in rtf1 to a file? also, please include all of the commondialog stuff. like i said, im a vb newbie, and this is really puzzeling me, so please help me out guys.
 
Hey,

the following Code is tested in VB 6. If you using VB 5 the code should to be similar.

First of all, you must place a Common Dialog Control on your Form. This Control is not shown in your normal tool box, so you must include it by the toolbar "components"
In the example below, the commondialog control is called ctrlCLMD.

The code, I have inserted is by using a command button. I think you use a menuitem. But I don't think, that this should be a problem, to alter the code by yourself.
And here comes the code:

Private Sub cmdSave_Click()
ctrlCMD.Filter = "Richtext (*.rtf) |*.rtf |Text (*.txt) |*.txt "
ctrlCMD.ShowSave
If Right(ctrlCMD.FileName, 3) = "rtf" Then
rtf1.SaveFile ctrlCMD.FileName, rtfRTF
Else
rtf1.SaveFile ctrlCMD.FileName, rtfText
End If
End Sub

If you want to change the startdirectory of the commondialog, insert the following line in your code, before the ShowSave command is sent:

ctrlCMD.initdir = <Path of Initdir>


Kostarsus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top