SaveDocument PowerScript function
Description
Saves the contents of a RichTextEdit control in a file. You
can specify either rich-text format (RTF) or text format for the
file.
Controls
RichTextEdit controls
Syntax
1 |
<span>rtename</span>.<span>SaveDocument</span> ( <span>filename</span> {, <span>filetype</span> {, <span>encoding</span> }} ) |
Argument |
Description |
---|---|
rtename |
The name of the RichTextEdit control |
filename |
A string whose value is the name of the |
filetype |
A value of the FileType enumerated datatype
|
encoding (optional) |
Character encoding of the file to which The filetype argument must be set to
|
Return Values
Integer. Returns 1 if it succeeds and
-1 if an error occurs.
Usage
SaveDocument triggers a FileExists event
when the file you name already exists. If you do not specify a filetype, SaveDocument saves
the file as a text file if you specify a file name with the extension
.txt, as a Microsoft Word document if you specify
a file name with the extension .doc, and as
an RTF file if you specify a file name with the .rtf extension.
The format that you specify in the encoding argument
is valid only if you specified FileTypeText! for the filetype argument. SaveDocument saves
text in ANSI format only for all other file types.
Examples
This code for a CommandButton saves the document
in the RichTextEdit rte_1:
1 |
integer li_rtn |
1 |
li_rtn = rte_1.<span>SaveDocument</span>("c: est.rtf", & |
1 |
FileTypeRichText!) |
If the file TEST.RTF already
exists, PowerBuilder triggers the FileExists event with the following
script. OpenWithParm displays a response window
that asks the user if it is OK to overwrite the file. The return
value from FileExists determines whether the file is saved:
1 |
OpenWithParm( w_question, & |
1 |
"The specified file already exists. " + & |
1 |
"Do you want to overwrite it?" ) |
1 |
IF Message.StringParm = "Yes" THEN |
1 |
RETURN 0  // File is saved |
1 |
ELSE |
1 |
RETURN -1 // Saving is canceled |
1 |
END IF |
This code for a CommandButton saves the document
in the RichTextEdit rte_1 in a text
file with UTF-16LE encoding:
1 |
integer li_rtn |
1 |
li_rtn = rte_1.<span>SaveDocument</span>("c: est.txt", & |
1 |
   FileTypeText!, EncodingUTF16LE!) |