Promotic
WikipediaLinkedInYoutubeTwitterFacebook

FileTextWrite - method of object Pm

Description:
Storing the variable (or the array of variables) into the text file.
Syntax:
FileTextWrite(sFile As String, vValue As Variant, [sOptions As String]) As Boolean
Calling:
b = Pm.FileTextWrite(sFile, vValue, sOptions)
Parameters:
sFile(String) File name (with the path). If the file doesn't exist, it'll be created. If a full path is not entered, it is completed relatively according to the application file 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 String type or 1-dim. Array of these variables.
In case of String type the content of it is written and the 'new line' character is added after it (see vbCrLf constant).
In case of the Array each item of it is written on a new line but after the last item the 'new line' is not added.
sOptions[optional] (String) Indication how to save.    For example "mode:add;charset:utf-8;".
mode:xxx; (optional) - The option sets the behaviour of writing to an existing file.
mode:new; (default) - If the file doesn't exist, a new one is created. If the file does exist, its content is erased and overwritten with a new one.
mode:add; - If the file doesn't exist, a new one is created. If the file does exist, the content of the stored variable is added to the existing file content.
charset:xxx; (optional) - The option sets 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 - operation passed successfully
false - operation failed
Note:
This method is not functional for Web Panels.
Example1:
Dim data
data = Array("Hallo", 1.23, "bye-bye")
Pm.FileTextWrite "#data:File.txt", data, 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.
Dim aData, sRow
' Create the file with 1 row:
aData = Array(12.2, 14, "row1", 1, 0)
sRow = Pm.StringFormat("%3.2f;%d;%s;%d;%d;", aData)
Pm.FileTextWrite "#data:File.csv", sRow
' Add the 2nd row:
aData = Array(14.8, 21, "row2", 0, 1)
sRow = Pm.StringFormat("%3.2f;%d;%s;%d;%d;", aData)
Pm.FileTextWrite "#data:File.csv", sRow, "mode:add;"
Example3:
This method can be used for printing a single line of text on a printer (see How to print in 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 PmSequencer object.

New row offset (vbCrLf) is not necessary for row printing. It can be used for printing multiple lines ("Text row1" & vbCrLf & "Text row2").

Pm.FileTextWrite "lpt1:", "Text row" & vbCrLf, true
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