Promotic

LoadFromFile - method of the PmaDataTable object

Description:
Loading data for this object from the file of the INI or CSV type.
Syntax:
Boolean LoadFromFile(String sFile, String sParams)
Parameters:
sFile(String) The file name with the path for loading the data. File must not have the "ini" or "csv" extension, the file type is determined by the filetype 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 and folders.
sParams(String) Additional parameters that define the way of loading from the file. Entries are in the KeyVal format, for example "filetype:ini;fmt:trans;rowname:boiler;".
"filetype:xxx;" (mandatory) - Specifies the type of the file specified in the sFile parameter
ini - type is a INI file.
csv - type is a CSV file. It is the multilined file of text values, for example, separated by semicolon. It is commonly used, for example, in the MsExcel program.
"fmt:xxx;" (optional) - Specifies the format of stored data in the file.
The default value is "fmt:standard;".
The following formats are possible:
standard - The meaning depends on the file type:
csv - Values from rows of the CSV file are stored into corresponding rows in the table
ini - Sections of the INI file are the names of rows and keys of the INI file are the names of table columns. Example:
[r0]
colname1=boiler1
colname2=boiler2
[r1]
colname1=12
colname2=15
trans - Sections of the INI file are the names of table columns and keys of the INI file are the names of rows. Example:
[colname1]
r0=boiler1
r1=12
[colname2]
r0=boiler2
r1=15
"rowname:xxx;" (optional) - (only for INI) Specifies the name of the row.
If not set, then the "rowname:r;" value is presumed. The name of the row is created by this text amended by the row index, for example if it is the "rowname:rrr;", then the names of rows are "rrr0", "rrr1", etc.
"colnameheader:xxx;" (optional) - (only for CSV)
no (default) - in the first row of the file there are stored the data.
yes - in the first row of the file there aren't any data but names of columns.
"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 line).
"date.fmt:xxx;" (optional) - Date/time format. The allowed values are:
system (default) - the date/time format is set by Windows OS settings (e.g. 22.11.2010 16:30:15).
pm - PROMOTIC date/time format with 1 second precision (e.g. 2010.11.22 16:30:15).
pmmili - PROMOTIC date/time format - precision 10 ms (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 Windows OS settings (e.g. 3,14).
dot - the decimal separator is a period (independently on Windows OS setting) (e.g. 3.14).
comma - the decimal separator is a comma (independently on Windows OS setting) (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.
Return value:
true - Loading proceeded successfully (at least one value has been loaded into the table)
false - Otherwise
Note:
This method doesn't change the number and names of columns and thus it is important to have ready the columns when calling this method (e.g. on the "Columns" tab or by the InsertCol method).
The method loads data from the file and stores them in the existing rows in the table (from beginning of the table). If there are more rows in the file than in the table, then the number of rows in the table increases to the required number. Then it is possible to load data for example into the table that has no row. But on loading the maximum number of rows that is set on the "DataTable" tab, mustn't be exceeded.
Loading from the file is performed per rows or per columns (according to the fmt parameter). If the end of the row/column is encountered, then it is passed over to the next one. Thus not all values of the row/columns need be saved into the file.

"Read only" columns:
Each cell is empty at the beginning. The cell is considered empty also if it contains numeric value 0 or an empty string "". New value can be written into such cell. After writing a non-zero value into the "Read only" column the cell is "locked". "Locked cell" becomes a constant and cannot be written again. Other still "unlocked" cells can be written into as needed. Methods that write into multiple cells simultaneously will write the values only into "unlocked cells" while the content of "locked" cells remains unchanged.
Example1:
Setting the object from the configuration file CfgData.csv saved in the application folder. The separator of values is semicolon, the decimal separator is a period and the date is formated as PROMOTIC system syntax.
JavaScriptVBScriptSelect and copy to clipboard

var oDataTable = pMe.Pm("/DataTable");
oDataTable.LoadFromFile("#app:CfgData.csv", "filetype:csv;colnameheader:no;delimiter:semicolon;real.dsep:dot;date.fmt:pm;");
Example2:
Setting the object from the configuration file CfgData.ini in the application folder.
JavaScriptVBScriptSelect and copy to clipboard

var oDataTable = pMe.Pm("/DataTable");
oDataTable.LoadFromFile("#app:CfgData.ini", "filetype:ini;rowname:boiler;");

History:
Pm8.03.15: Fixed bug: The method sometimes failed while reading empty CSV file.
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.