Update cookies preferences
Promotic

FileTextWrite - method of the Pm object

Description:
Saving the value (or array of values) into the text file.
Syntax:
Boolean FileTextWrite(String sFile, Variant vValue, [String sOptions])
Parameters:
sFile(String) The file name with the path.
If the file does not exist, then it'll be created.
If a full path is not entered, then it is completed relative to the application folder.
It is recommended to use the PROMOTIC path syntax - see PROMOTIC path to files or folders.
vValue(Variant) Written variable.
It can be of a single type convertible to the value of the String type or 1-dimensional array of these variables.
For String type the content of it is written and the 'new line' character is added after it (see vbCrLf constant).
For Array type each item of it is written on a new line but after the last item the 'new line' character is not added.
sOptions[optional] (String) Specifies how to save. For example "mode:add;charset:utf-8;sep:no;".
mode:sss; (optional) - The option specifies the behavior on writing to an existing file.
mode:new; (default) -
If the file does not exist, then a new file is created.
If the file exists, then its content is erased and overwritten with a new one.
mode:add; -
If the file does not exist, then a new file is created.
If the file exists, then the content of the stored variable is added to the existing file content.
sep:sss; (optional) - Option specifies whether the array items and the following entries will be separated.
sep:newline; (default) - The array items and the following entries will be separated by a new line.
sep:no; - The array items and the following entries are not separated. Only the content of texts is written, no additional characters are added. The characters indicating new rows must be contained in the written texts.
charset:sss; (optional) - The option specifies the charset. See: Unicode character encoding description.
charset:ansi; (default) - The text content will be stored in ANSI code page which is active in Windows OS at the moment (e.g. windows-1250).
charset:utf-8; - The text content will be stored in Unicode UTF-8 encoding (independent on Windows OS active code page).
charset:utf-16; - The text content will be stored in Unicode UTF-16 encoding (independent on Windows OS active code page).
bom:nnn; (optional) - Option specifies whether a BOM tag (3 bytes) is placed to the beginning of a text file that allows the identification of Unicode charset.
bom:1; (default) - A BOM tag is placed to the beginning of the new file that allows identification of the Unicode charset.
bom:0; - The BOM tag for Unicode charset identification is not added to the beginning of the file. This option is suitable for HTML or XML files, where the BOM is not added.
Return value:
true - on success
false - on error
Note:
This method is not functional in Web panels.
Example1:
JavaScriptVBScriptSelect and copy to clipboard

var arr = Pm.Array1("Hallo", 1.23, "bye-bye");
Pm.FileTextWrite("#app:File.txt", arr);
Example2:
The FileTextWrite method can be used for creating a file in the CSV format.
In this example the simple file.csv file will be created. The file will have 2 rows and on each row there will be 5 values separated by semicolon. The StringFormat method is used for formatting the row. Such created file can be read by the Pm.FileCsvRead method.
JavaScriptVBScriptSelect and copy to clipboard

var aData, sRow;

// Creates the file with 1 row:
aData = Pm.Array1(12.2, 14, "row1", 1, 0);
sRow = Pm.StringFormat("%3.2f;%d;%s;%d;%d;", aData);
Pm.FileTextWrite("#app:File.txt", sRow);

// Adds the 2nd row:
aData = Pm.Array1(12.2, 14, "row2", 1, 0);
sRow = Pm.StringFormat("%3.2f;%d;%s;%d;%d;", aData);
Pm.FileTextWrite("#app:File.txt", sRow, "mode:add;");
Example3:
This method can be used for printing a single line of text to a printer (see How to print in the PROMOTIC system).
The method is functional only on printers that support the text mode and parallel LPTn port (some network printers).
The method is synchronous and returns the transmission result. The execution may take a significant ammount of time and block the application functionality and therefore it is handy to use it in the PmaSequencer object.
New row offset (vbCrLf or "\n") is not necessary for row printing. It can be used for printing multiple lines:
JavaScriptVBScriptSelect and copy to clipboard

Pm.FileTextWrite("lpt1:", "Text row1 \n Text row2", "mode:add;");

History:
Pm9.00.17: New bom:nnn; parameter enables/disables the placement of the BOM tag to the beginning of the new file.
Pm9.00.16: New sep:sss; parameter allows to set separator of items and following entries.
PROMOTIC 9.0.31 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- FileTextWrite
 
 
- LN2
- PI
- Pow
- Sin
- Tan
© MICROSYS, spol. s r.o.