Update cookies preferences
Promotic

FileCsvRead - method of the Pm object

Description:
Parameterized reading the data from the CSV - text format for data exchange file.
Syntax:
Variant FileCsvRead(String sFile, String sFields, String sParams)
Parameters:
sFile(String) File to read. Regardless of whether this parameter is set or not, it is possible to open the window for file selection by setting the fileselect parameter.
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.
sFields(String) Specifies which columns will be read from the file and of which data types the read data will be. For example "filecols:0,1,2,3;datatypes:string,double,string,string;".
filecols - Specifies which columns of the source CSV file will be included into the output array of values. If set filecols:all; (default), then all columns are included in the same order.
A list of numeric indexes - each column of the output array of values has the index (order) in the source CSV file. Each column of the output array can be read from any column of the source CSV file. It means that the list must have as many items as the resulting matrix number of columns.
If set filecols:all; (default) then all columns are read.
If set, for example, filecols:0,1,3,8;, then only those columns from the file that are stated here by index (zero-based index) are read.
datatypes - The list of column data types of the output value array. The column data type specifies the way of reading data of the corresponding column of the CSV file. The defined column data types and the order must correspond with the output data array. It 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. Available data types of columns: string, byte, integer, bool, single, double. For example, datatypes:string,integer,bool,single;
If not set, then is string.
sParams(String) Specifies the way or reading the data from the file. For example "fileselect:yes;colnameheader:yes;delimiter:comma;"
"fileselect:xxx;" (optional)
yes - by calling the method the window for file selection 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 of 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 of the file).
"delimiter:xxx;" (optional) - (only for CSV) The separator of values in the CSV file. The allowed values are:
semicolon (default) - the separator is a semicolon.
comma - the separator is a comma.
space - the separator is a space.
tab - the separator is a tab.
number - i.e. the separator is defined as a number of the ASCII character (in decimal), for example "delimiter:124;" means the "|" separator (vertical bar).
"lastcolsep:xxx;" (optional)
yes - On 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.
Return value:
- If more than one column is read from the file then returns 2-dimensional array.
- If only one column is read from the file then returns 1-dimensional array.
- If reading the data failed then returns: null for JavaScript or Empty for VBScript (it can be tested by the Pm.IsValid method).
Note:
The FileCsvWrite method serves for creating and writing the data into the CSV file. The FileTextWrite method also can be used (see Example2 of this method).

This method is not functional in Web panels.
See also:
Example1:
The method displays the the window for file selection (the preset file is data.csv stored in the application folder), reads the data of the selected file from all columns. The values in the file are separated by semicolon and the file does not contain the column names in the first row.
JavaScriptVBScriptSelect and copy to clipboard

var vData = Pm.FileCsvRead("#app:data.csv", "filecols:all;", "delimiter:semicolon;colnameheader:no;fileselect:yes;");
if (Pm.IsValid(vData))
{
// ... If the data were read successfully
}
Example2:
The methodreads the data from the data.csv file (name,value,unit,note), stored in the application folder. It reads three columns with swapped order (name,note,value, i.e. columns 0,3,1) and the result will be stored into the vData array. The values in the output array are of the following data types string, string and double. The values in the file are separated by semicolon and the file does not contain the column names in the first row.
JavaScriptVBScriptSelect and copy to clipboard

var sParams = "delimiter:semicolon;colnameheader:no;";
var vData = Pm.FileCsvRead("#app:data.csv", "filecols:0,3,1;datatypes:string,string,double;", sParams);
if (Pm.IsValid(vData))
{
// ... If the data were read successfully
}

History:
Pm8.00.00: Allows to enter arbitrary separator type ("delimiter:xxx;").
PROMOTIC 9.0.31 SCADA system documentation MICROSYS, spol. s r.o.

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