FileWriteFields() function
- Last UpdatedJul 22, 2024
- 2 minute read
Writes the values contained in a series of tagnames to a csv file. You can use this function to save a set of tagname values.
Commas are the only supported delimiter.
Syntax
[result = ] FileWriteFields (filename, offset, starttag, numberoffields)
Parameters
filename
Name of the csv file to write the data to. A new file is created if it does not previously exist. A literal string value, a message tagname, or a string expression.
offset
Location (in bytes) in the file to start writing to. Use -1 to write to the end of the file (append). A literal integer value, integer tagname, or integer expression.
starttag
Name of the first tagname that contains the first data item to be written. The tagname must be enclosed with double quotes and end in a number, such as "MyTag1". A literal string value, message tagname (such as a message tagname containing the value "MyTag1") or a string expression.
numberoffields
Number of data items to write to the csv file. A literal integer value, integer tagname, or integer expression. The first data item is written from the tagname defined in the starttag parameter to the file, subsequent data items from tagnames with the incremented numeral suffix of the starttag parameter (MyTag1, MyTag2, MyTag3, ...).
Return value
Optional new file offset (in byte) after writing the data. This can be used to write the next set of data.
Example(s)
A series of InTouch tags is defined as follows:
|
Tagname |
Data Type |
Value |
|---|---|---|
|
RecipeTag1 |
Message |
Flour |
|
RecipeTag2 |
Real |
27.23 |
|
RecipeTag3 |
Integer |
14 |
|
RecipeTag4 |
Discrete |
1 |
This script writes the values contained in RecipeTag1 to RecipeTag4 to the csv file c:\set.csv.
FileWriteFields("c:\set.csv",0,"RecipeTag1",4);
So that the file c:\set.csv will contain the following data:
Flour,27.23,14,1