Promotic

SaveToFile - method of the PmaTrendGroup object

Description:
Saving data of this object into the file of the CSV or DBF type.
All columns according to setting the sWhat parameter are stored and the data according to setting the vFilter parameter.
Syntax:
Boolean SaveToFile(String sWhat, String sFile, Variant vFilter, String sParams)
Parameters:
sWhat(String) Specification of the variable (or of variables) whose stored values have to be returned. It is possible to enter, for example:
"a1;" or "a1;a2;a3;" if an array of variables of the "Data" tab has to be returned or
"time;" if an array of the time has to be returned or
"attr;" if an array of the record attributes has to be returned or
"*;" if all columns including the time and attribute columns have to be returned or
"*data;" if all data columns have to be returned. In this case, for example, time;*data; means returning the time column and all data columns.

At the variables it is necessary to keep the order by the order on the tab. For example, if the order of variables is a1,a2,a3,... on the tab, then it is possible to enter, for example, "a1;a3;" in the parameter but "a3;a1" is wrong.
Time selection can be changed by entering "time:winter;" and then all time values are returned in the "standard time" otherwise they are in the "local time".
sFile(String) The file name with the path into which the data have to be saved.
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.
vFilter(Variant) Value that defines, for example, the time range of the got data (time from, time to, number of points, etc.), eventually if the data has to be filtered by the value. It is created by calling the methods CreateFilter, AddFilter.
sParams(String) Text list of parameters that define the way of saving into the file. Entries are in the KeyVal format, for example "filetype:csv;fmt:standard;".
"filetype:xxx;" (mandatory) - Specifies the type of the file specified in the sFile parameter. The following file types are possible:
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.
dbf - the type is a DBF file in the dBase III format. It is commonly used, for example, by the MsExcel program.
"fmt:xxx;" (optional) - Specifies the format of the data stored in the file. The following formats are possible:
standard - (only for CSV) values from rows of the CSV file are stored into corresponding rows in the table
"head:xxx;" (optional) - (only for CSV)Specifies whether the single-line heading with the columns names is stored in the file. The allowed values are:
no (default) - Heading is not inserted.
name - Heading is inserted, there are variable names in the heading. (Values of the PmVar.Name property).
displayname - Heading is inserted. There are variable names for displaying in the heading (values of the ExtTrend.DisplayName property).
"timeorder:xxx;" (optional) - Specifies whether the rows of values are sorted by the time ascending or descending
asc (default) - rows of values are sorted by the time ascending
desc - rows of values are sorted by the time descending
"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 - saving proceeded successfully
false - Otherwise
Example:
Saving the last hour data into the Data.csv file. The first row contains the value identifiers, the data separator is semicolon, the decimal number separator is used according to the Windows OS setting and the date format also defined by Windows OS.
JavaScriptVBScriptSelect and copy to clipboard

var tNow = Pm.Time;
var oTrend = pMe.Pm("/Trends");
var vFilter = oTrend.CreateFilter(tNow - 1 / 24, 1, tNow, 1, -1);

if (oTrend.SaveToFile("time;a1;a2;a3;", "Data.csv", vFilter, "filetype:csv;head:name;"))
{
// Data.csv file created OK
}

History:
Pm8.00.12: The method for DBF format returns the true value on success.
Pm8.00.09: Generalization by:
- the possibility to save data into dBase (DBF) file, see "filetype:dbf;".
- the possibility to define the decimal separator of the real number (comma or full stop), see the "real.dsep:xxx;" parameter.
- the possibility to define the format of date and time, see the "date.fmt:xxx;" parameter.
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

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