save file as .txt or as .rtf in rich text box 
Author Message
 save file as .txt or as .rtf in rich text box

To all:

I am trying to create a common dialog control based save file function
that allows the file to be saved as either a text file or a rich text
file. I can do it as either one, but am mystified as to how to allow a
choice between the two. The code is below and I'd be greatful for
suggestions as to how to make this work

Thanks

Ron Lesser

Private Sub mnuFileSaveClick()

CommonDialog1.CancelError = True
On Error GoTo ErrHandle

CommonDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Files
(*.rtf)|*.rtf| All Files (*.*)|*.*|"

CommonDialog1.Flags = _
    cdlOFNCreatePrompt + cdlOFNOverwritePrompt + _
    cdlOFNPathMustExist + cdlOFNHideReadOnly + cdlOFNLongNames

CommonDialog1.fileName = Right(CommonDialog1.fileName,
(Len(CommonDialog1.fileName) - (InStrRev(CommonDialog1.fileName, "\",
-1, 1))))

CommonDialog1.fileName = Left(CommonDialog1.fileName, _
(InStr(CommonDialog1.fileName, ".") - 1))

CommonDialog1.InitDir = GetSetting("eegrprt", "values", "DirSaveAs")

CommonDialog1.ShowSave

' on the next line: , 1 saves as text file
' as it is or, 0 saves as rtf
'I'm trying to allow a choice between the two
rtbSelection.SaveFile CommonDialog1.FileTitle    

On Error GoTo 0
Exit Sub

ErrHandle:
   If Not Err = cdlCancel Then
      Resume Next
   End If

End Sub



Thu, 27 Sep 2001 03:00:00 GMT  
 save file as .txt or as .rtf in rich text box
use your usual save dialog box code, but at the very beginning of the save
code insert this line:

commondialog1.filters="Rich Text File(*.rtf)|*.rtf| Text File(*txt)|*.txt"

of course chang the name of the dialog box to whatever you named it, and it
will then display only the two options in the box that displays file type.
then it will save the file as whatever the user chooses.

Clint Knapp

Quote:
> To all:

> I am trying to create a common dialog control based save file function
> that allows the file to be saved as either a text file or a rich text
> file. I can do it as either one, but am mystified as to how to allow a
> choice between the two. The code is below and I'd be greatful for
> suggestions as to how to make this work

> Thanks

> Ron Lesser

> Private Sub mnuFileSaveClick()

> CommonDialog1.CancelError = True
> On Error GoTo ErrHandle

> CommonDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Files
> (*.rtf)|*.rtf| All Files (*.*)|*.*|"

> CommonDialog1.Flags = _
>     cdlOFNCreatePrompt + cdlOFNOverwritePrompt + _
>     cdlOFNPathMustExist + cdlOFNHideReadOnly + cdlOFNLongNames

> CommonDialog1.fileName = Right(CommonDialog1.fileName,
> (Len(CommonDialog1.fileName) - (InStrRev(CommonDialog1.fileName, "\",
> -1, 1))))

> CommonDialog1.fileName = Left(CommonDialog1.fileName, _
> (InStr(CommonDialog1.fileName, ".") - 1))

> CommonDialog1.InitDir = GetSetting("eegrprt", "values", "DirSaveAs")

> CommonDialog1.ShowSave

> ' on the next line: , 1 saves as text file
> ' as it is or, 0 saves as rtf
> 'I'm trying to allow a choice between the two
> rtbSelection.SaveFile CommonDialog1.FileTitle

> On Error GoTo 0
> Exit Sub

> ErrHandle:
>    If Not Err = cdlCancel Then
>       Resume Next
>    End If

> End Sub



Sun, 30 Sep 2001 03:00:00 GMT  
 save file as .txt or as .rtf in rich text box
Thanks, I'm using this line at the start, but my code doesn't seem to
work for me. It will change the extension to .rtf or .txt but if the
line is:  rtbSelection.SaveFile CommonDialog1.fileName
then, even if I save it as .txt, the actual file is a rich text file.

I can say, for instance rtbSelection.SaveFile CommonDialog1.fileName, 1
but then the file is saved as txt whether I want it that way or not. For
whatever reason, I can't get the code to recognize the extension that's
been selected and then save it that way.

The code I'm using is as follows, after a lot of tries. This at least
does the following, which I need for my particular app: it saves a file
as an 8.3. What I want is for the code to "llok at" the .3 that's been
selected and then save the file either as .rtf or .txt depending on
what's been selected.

The code:

Private Sub mnuFileSave_Click()

CommonDialog1.CancelError = True
On Error GoTo ErrHandle

'  the user starts with a template that is in .txt format. The format is
dictated by what the mainframe wants to see, and we have no control over
that; we just want it to be happy.

CommonDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Files
(*.rtf)|*.rtf| All Files (*.*)|*.*|"
CommonDialog1.Flags = _
    cdlOFNCreatePrompt + cdlOFNOverwritePrompt + _
    cdlOFNPathMustExist + cdlOFNHideReadOnly

'  this was done to assure that the file title was stripped to just
'  file name. This was done because sometimes the file was saved as '
8.3.3, and this I didn't want

CommonDialog1.fileName = Right(CommonDialog1.fileName,
(Len(CommonDialog1.fileName) - (InStrRev(CommonDialog1.fileName, "\",
-1, 1))))
CommonDialog1.fileName = Left(CommonDialog1.fileName, _
(InStr(CommonDialog1.fileName, ".") - 1))

' this sets some directories in the registry that automate where things
are saved.
CommonDialog1.InitDir = GetSetting("eegrprt", "values", "DirSaveAs")
CommonDialog1.ShowSave
' this saves the file title, tacks on .txt and saves as a text file
rtbSelection.SaveFile CommonDialog1.FileTitle, 1

On Error GoTo 0
Exit Sub

ErrHandle:
   If Not Err = cdlCancel Then
      Resume Next
   End If

End Sub

Any suggestions would be greatly appreciated.

Thanks

Ron Lesser

Quote:

> use your usual save dialog box code, but at the very beginning of the save
> code insert this line:

> commondialog1.filters="Rich Text File(*.rtf)|*.rtf| Text File(*txt)|*.txt"

> of course chang the name of the dialog box to whatever you named it, and it
> will then display only the two options in the box that displays file type.
> then it will save the file as whatever the user chooses.

> Clint Knapp


> > To all:

> > I am trying to create a common dialog control based save file function
> > that allows the file to be saved as either a text file or a rich text
> > file. I can do it as either one, but am mystified as to how to allow a
> > choice between the two. The code is below and I'd be greatful for
> > suggestions as to how to make this work

> > Thanks

> > Ron Lesser

> > Private Sub mnuFileSaveClick()

> > CommonDialog1.CancelError = True
> > On Error GoTo ErrHandle

> > CommonDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Files
> > (*.rtf)|*.rtf| All Files (*.*)|*.*|"

> > CommonDialog1.Flags = _
> >     cdlOFNCreatePrompt + cdlOFNOverwritePrompt + _
> >     cdlOFNPathMustExist + cdlOFNHideReadOnly + cdlOFNLongNames

> > CommonDialog1.fileName = Right(CommonDialog1.fileName,
> > (Len(CommonDialog1.fileName) - (InStrRev(CommonDialog1.fileName, "\",
> > -1, 1))))

> > CommonDialog1.fileName = Left(CommonDialog1.fileName, _
> > (InStr(CommonDialog1.fileName, ".") - 1))

> > CommonDialog1.InitDir = GetSetting("eegrprt", "values", "DirSaveAs")

> > CommonDialog1.ShowSave

> > ' on the next line: , 1 saves as text file
> > ' as it is or, 0 saves as rtf
> > 'I'm trying to allow a choice between the two
> > rtbSelection.SaveFile CommonDialog1.FileTitle

> > On Error GoTo 0
> > Exit Sub

> > ErrHandle:
> >    If Not Err = cdlCancel Then
> >       Resume Next
> >    End If

> > End Sub



Mon, 01 Oct 2001 03:00:00 GMT  
 save file as .txt or as .rtf in rich text box
Solved my problem (with a little help):

Dim Msg, Answer

If Right(CommonDialog1.fileName, 3) = "txt" Then
'MsgBox Right(CommonDialog1.fileName, 3)
rtbSelection.SaveFile CommonDialog1.FileTitle, 1
ElseIf Right(CommonDialog1.fileName, 3) = "rtf" Then
'MsgBox Right(CommonDialog1.fileName, 3)
rtbSelection.SaveFile CommonDialog1.FileTitle, 0
Else

   Msg = "You didn't give an extension. Save as a text file?"
   Answer = MsgBox(Msg, vbYesNo)   ' Get user response.
   If Answer = vbYes Then   ' Evaluate answer.
      rtbSelection.SaveFile CommonDialog1.FileTitle, 1   ' If Yes, show
form.
   Else
   Exit Sub
   End If
End If

Quote:

> use your usual save dialog box code, but at the very beginning of the save
> code insert this line:

> commondialog1.filters="Rich Text File(*.rtf)|*.rtf| Text File(*txt)|*.txt"

> of course chang the name of the dialog box to whatever you named it, and it
> will then display only the two options in the box that displays file type.
> then it will save the file as whatever the user chooses.

> Clint Knapp


> > To all:

> > I am trying to create a common dialog control based save file function
> > that allows the file to be saved as either a text file or a rich text
> > file. I can do it as either one, but am mystified as to how to allow a
> > choice between the two. The code is below and I'd be greatful for
> > suggestions as to how to make this work

> > Thanks

> > Ron Lesser

> > Private Sub mnuFileSaveClick()

> > CommonDialog1.CancelError = True
> > On Error GoTo ErrHandle

> > CommonDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Files
> > (*.rtf)|*.rtf| All Files (*.*)|*.*|"

> > CommonDialog1.Flags = _
> >     cdlOFNCreatePrompt + cdlOFNOverwritePrompt + _
> >     cdlOFNPathMustExist + cdlOFNHideReadOnly + cdlOFNLongNames

> > CommonDialog1.fileName = Right(CommonDialog1.fileName,
> > (Len(CommonDialog1.fileName) - (InStrRev(CommonDialog1.fileName, "\",
> > -1, 1))))

> > CommonDialog1.fileName = Left(CommonDialog1.fileName, _
> > (InStr(CommonDialog1.fileName, ".") - 1))

> > CommonDialog1.InitDir = GetSetting("eegrprt", "values", "DirSaveAs")

> > CommonDialog1.ShowSave

> > ' on the next line: , 1 saves as text file
> > ' as it is or, 0 saves as rtf
> > 'I'm trying to allow a choice between the two
> > rtbSelection.SaveFile CommonDialog1.FileTitle

> > On Error GoTo 0
> > Exit Sub

> > ErrHandle:
> >    If Not Err = cdlCancel Then
> >       Resume Next
> >    End If

> > End Sub



Mon, 01 Oct 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. save file as .txt or as .rtf in rich text box

2. Saving Rich Text Box Content to .RTF File

3. Saving Rich Text Box Content to .RTF file

4. Saving Rich Text Box to .RTF File

5. Rich Text File (.RTF) -Can't copy multiple .rtf files

6. Rich Text File (.RTF) -Can't copy multiple .rtf files (VB 6.0 Enterprise)

7. opening / saving files with MS rich text box control (viewing open files)

8. Copying text in .rtf format from one rich text box to another

9. Saving the content of several RTF text boxes on single file

10. Saving Rich Text Format (RTF) in Oracle 10g using PL/SQL via VB/ASP.NET

11. saving rich text box as plain text

12. Saving Rich Text Box Control as PLAIN TEXT!!!!

 

 
Powered by phpBB® Forum Software