i have a question on the commondialog conponent.....I need to know how to load a txt file that i pik from the commondialog into a richtextbox.....Please reply...Thanx Michael
Printable View
i have a question on the commondialog conponent.....I need to know how to load a txt file that i pik from the commondialog into a richtextbox.....Please reply...Thanx Michael
Try this.
Code:CommonDialog1.ShowOpen
RichTextBox1.LoadFile CommonDialog1.FileName, rtfText
The above example was short for simplicity sake. This next example is well commented and will handle errors (if cancel is selected).
Code:On Error Resume Next
'Generate an error when cancel is pressed
CommonDialog1.CancelError = True
'Define the file-types
CommonDialog1.Filter = "Text Files (*.txt)|*.txt"
'Display the Open dialog
CommonDialog1.ShowOpen
'Make sure an error doesn't occur
If Err <> 32755 Then
'Loads the file. Change rtfText to rtfRTF if you want the file to
'be in RichText format
RichTextBox1.LoadFile CommonDialog1.filename, rtfText
End If
Thanx you two....I really appreciate it.
I need the code just like above but to save it...sorry so many questions..Thanx S.ystem
Yep, you just have to use showsave instead of showload, and savefile intead of loadfile
Code:CommonDialog1.ShowSave
RichTextBox1.SaveFile CommonDialog1.filename, rtfText