Owning Palette: File I/O VIs and Functions
Requires: Base Development System
Formats string, numeric, path, or Boolean data as text and writes the text to a file. If you wire a file refnum to the file input, writing begins at the current file position. To append to an existing file, open the file and set the file position to the end of the file by using the Set File Position function. Otherwise, the function will open the file and write to the beginning of the file. This function does not work for files inside an LLB.
|format string specifies how to convert the input arguments. Defaults match the data type of the input arguments. Right-click the function and select Edit Format String from the shortcut menu to create and edit the format string.
This input accepts a maximum of 255 characters.
|input file can be a refnum or absolute file path. If it is a refnum, this node opens the file specified by the refnum. This function creates the specified file if it does not already exist. The default is to display a file dialog box and prompt you to select a file.
If you specify an empty or relative path, this function returns an error.
|error in describes error conditions that occur before this node runs. This input provides standard error in functionality.|
|input 1..n specifies the input parameters to be converted. Each input can be a string, path, enumerated type, time stamp, or any numeric data type. You cannot use arrays and clusters with this function.|
|output file refnum is the refnum of the file that the VI read. You can wire this output to another file function, depending on what you want to do with the file. The default is to close the file if it is referenced by a file path or selected from the file dialog box. If input file is a refnum, LabVIEW assumes that the file is still in use until you close it.|
|error out contains error information. This output provides standard error out functionality.|
Increase the number of parameters by right-clicking the function and selecting Add Parameter from the shortcut menu or by resizing the function.
You can use this function to determine the order in which the data appears in the file.
This function converts new lines, or \n, in the format string into the platform-specific end-of-line character, for example, CR/LF on Windows, CR on Mac OS X, and LF on Linux. If you do not want to convert new lines into the end-of-line character, use the Format Into String function and wire the resulting string output to the text input of the Write to Text File function. Then right-click the Write to Text File function and remove the checkmark next to the Convert EOL shortcut menu item.
By default, this function uses the order of the inputs to populate the format specifiers, or percent codes, in the Format String. However, you can use a number followed by a dollar sign ($) within a percent code to specify exactly which input to use for that percent code. For example, the percent code %3$d uses the third input regardless of how many percent codes appear before it in the format string.
As a further example, refer to the following block diagram:
The following input combinations illustrate the effects of the $ specifier:
|Input 1||Input 2||Format String||Data in Output File||Comments|
|first||second||%s %s||first second||Format String does not use the $ specifier, so the function populates the percent codes in input order.|
|first||second||%2$s %1$s||second first||Format String uses the $ specifier to display the inputs in a different order than their input order.|
|first||second||%1$s %1$s %1$s||first first first||Format String uses the $ specifier to display the first input multiple times and ignore the second input.|
You can use other special characters besides the $ to configure how this function populates the percent codes in format string.
Refer to the Format Into File and Scan From File VI in the labview\examples\File IO\Text (ASCII) directory for an example of using the Format Into File function.