Promotic
WikipediaLinkedInYoutubeTwitterFacebook

FileCsvWrite - method of object Pm

Description:
Parameterized writing of the data into a CSV file.
Syntax:
FileCsvWrite(sFile As String, sFields As String, sParams As String, aValues As Array) As Boolean
Calling:
bResult = Pm.FileCsvWrite(sFile, sFields, sParams, aValues)
Parameters:
sFile(String) File to write. Independently whether this parameter is set or not, it is possible to open the window for choosing a disk file by setting the fileselect parameter. 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.

sFields(String) Defines how the columns from the source data array will be saved in the output CSV file. For example "filecols:0,1,2,3;appnames:name,value,unit,note;".
filecols - Defines how the columns from the source data array will be saved in the output CSV file. If filecols:all; is set (default) then all columsn will be saved observing the column sequence.

A list of number indexes. There is a subsequentialy defined (sequence) index for each column of the source data array to be used for the output CSV file. Each column of the source data array can be saved into arbitrary column of the output CSV file or even omited (indexu value -1). This means that the list must contain as many items as is the number of columns of the source value array. The number of columns in the output CSV file is defined by the maximal index value (+1) in the list. Empty columns may appear when mapping the source array columns sequence into the output CSV file.

For example, filecols:0,9; means that 2 columns of the source data array will be mapped into 10 (9+1) columns in the output CSV file, where the columns with indexes from 1 to 8 will be empty.

For example, filecols:0,2,-1,1; means that 4 columns of the source data array will be mapped into 3 (2+1) columns in the output CSV file, and the column with sequence index 2 of the source data array will not be saved at all.

appnames - A list of column names of the source data array. The defined column names and order must correspond with the source data array. This means that the list must contain as many items as is the number of columns of the output value array. The columns in the source CSV file may differ from the output value array, if the filecols column filter is used. The column names are necessary for creating the header of the CSV file.
sParams(String) Specifies the way of saving the data into the file. For example: "fileselect:yes;colnameheader:yes;delimiter:comma;"
"fileselect:xxx;" (optional)
yes - by calling the method the window for choosing a disk file is opened independently on setting the sFile parameter.
no (default)
"colnameheader:xxx;" (optional)
yes - in the first row of the file there are no data but names of individual columns.
no (default) - already in the first row of the file the data are saved.
"swap:xxx;" (optional)
yes (default) - columns from the file are saved as rows in the resulting matrix (in the data(i,j) cell there is the value of the i-th column and j-th row in the file).
no - rows from the file are saved as rows in the resulting matrix (in the data(i,j) cell there is the value of the i-th row and j-th column in the file).
"delimiter:xxx;" (optional) - (only for CSV) The separator of values in the CSV file. The allowed values are:
semicolon (default) - the delimiter is a semicolon.
comma - the delimiter is a comma.
space - the delimiter is a space.
tab - the delimiter is a tab.
number - i.e. the separator is defined as a decimal number of the ASCII character, for example "delimiter:124;" represents the "|" separator (vertical line).
"date.fmt:xxx;" (optional) - Date/time format. The allowed values are:
system (default) - the date/time format is set by OS Windows settings (e.g. 22.11.2010 16:30:15).
pm - PROMOTIC date/time format with 1 second accuracy (e.g. 2010.11.22 16:30:15).
pmmili - PROMOTIC date/time format with 1 millisecond accuracy (e.g. 2010.11.22 16:30:15.250).
real - data type of date/time format Date as a real number (e.g. 41392.123456789).
"real.dsep:xxx;" (optional) - (only for CSV) The format of decimal separator for real numbers. The allowed values are:
system (default) - the decimal separator is defined by OS Windows settings (e.g. 3,14).
dot - the decimal separator is (regardles on OS Windows settings) a period (e.g. 3.14).
comma - the decimal separator is (regardles on OS Windows settings) a comma (e.g. 3,14).
"lastcolsep:xxx;" (optional)
yes - When writing, the separator is added after the last value on the row, when reading, the empty value at the end of each row is ignored. From the CSV file standard point of view, this is not correct.
no (default) - The separators are present only between values on the same row, not at the end. From the CSV file standard point of view, this is correct.
aValues(Array) Source data array (2-dimensional Array) that will be saved into the output CSV file.
Return Values:
true - operation passed successfully
false - operation failed
Note:
For reading data from CSV file the FileCsvRead method is used.
 
This method is not functional for Web Panels.
Example1:
The method displays the window for choosing a file (the default file is data.csv stored in the application folder). The data from the source array aValues are saved into the selected file. All columns are saved, the values in the file are separated by semicolon and the file does not include the column names in the first row.
Dim bResult
bResult = Pm.FileCsvWrite("#app:data.csv", "", "fileselect:yes;", aValues)
Example2:
The method saves data from the source array aValues into the data.csv file in the application folder. The values in the file are separated by semicolon and the file includes the column names in the first row. The source data array has 4 columns (name, value, unit, note).

a) Save all columns from the source data array with defeinition of column names and data types.

Dim bResult
bResult = Pm.FileCsvWrite("#app:data.csv", "filecols:all;appnames:name,value,unit,note;", "colnameheader:yes;", aValues)
or
bResult = Pm.FileCsvWrite("#app:data.csv", "filecols:0,1,2,3;appnames:name,value,unit,note;", "colnameheader:yes;", aValues)

b) Save only 3 columns (without the "unit" column) from the source data array with mixed sequence in the output CSV file (name,note,value), with definition of the column names nad data types. Beacause the source data array is identical, the list of column names remains the same.

bResult = Pm.FileCsvWrite("#app:data.csv", "filecols:0,2,-1,1;appnames:name,value,unit,note;", "colnameheader:yes;", aValues)
Navigation:
 
- Pm
 
- Abs
- Cos
- E
- Exp
- FileCsvWrite
 
 
- LN2
- PI
- Pow
- Sin
- Tan
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice