Promotic
WikipediaLinkedInYoutubeTwitterFacebook

FileTextWrite - method of the Pm object

Description:
Saving the variable (or the array of variables) 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 and folders.

vValue(Variant) Written variable.

It can be of a single type convertible into 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;".
mode:xxx; (optional) - The option specifies the behaviour of writing to an existing file.
mode:new; (default) -
If the file does not exist, then a new one 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 one is created.
If the file exists, then the content of the stored variable is added to the existing file content.
charset:xxx; (optional) - The option specifies the charset. See: Unicode character coding description.
charset:ansi; (default) - The text content will be stored in ANSI code page which is active in OS Windows at the moment (e.g. windows-1250).
charset:utf-8; - The text content will be stored in Unicode UTF-8 encoding (independent on OS Windows active code page).
charset:utf-16; - The text content will be stored in Unicode UTF-16 encoding (independent on OS Windows active code page).
Return values:
true - on success
false - on error
Note:
This method is not functional in Web panels.
Example1:
JavaScriptVBScriptSelect and copy to clipboard

var arr = Pm.CreatePmArray().Array1("Hallo", 1.23, "bye-bye");
Pm.FileTextWrite("#app:File.txt", arr, false);
Example2:
The FileTextWrite method can be used for creating a file of 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.CreatePmArray().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.CreatePmArray().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, 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", true);
PROMOTIC 9.0.15 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.Tavičská 845/21 703 00 Ostrava-Vítkovice