Scan From File

Scans text in a file for string, numeric, path, and Boolean data, converts the text to a data type, and returns a duplicated refnum and the converted outputs in the order scanned. You can use this function to read all the text in the file. However, you cannot use this function to determine a starting point for the scan. To do so, use the Read Characters from File VI and the Scan From String function. Details

format string specifies how to convert the input string into the output arguments. The default is to scan the string according to default behavior for the data types of the outputs wired. Right-click the function and select Edit Scan String from the shortcut menu to create and edit the format string.
input file can be a refnum or file path. If it is a refnum, this node opens the file specified by the refnum. The default is to display the Open File dialog box and prompt you to select a file. If the file does not already exist, it will be created.
error in describes error conditions that occur before this VI or function runs. The default is no error. If an error occurred before this VI or function runs, the VI or function passes the error in value to error out. This VI or function runs normally only if no error occurs before this VI or function runs. If an error occurs while this VI or function runs, it runs normally and sets its own error status in error out. Use the Simple Error Handler or General Error Handler VIs to display the description of the error code. Use error in and error out to check errors and to specify execution order by wiring error out from one node to error in of the next node.
status is TRUE (X) if an error occurred before this VI or function ran or FALSE (checkmark) to indicate a warning or that no error occurred before this VI or function ran. The default is FALSE.
code is the error or warning code. The default is 0. If status is TRUE, code is a non-zero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning. The default is an empty string.
default 1..n specifies the default for the output parameters. If the input value cannot be scanned from the string, the function uses the default. If default 1 is left unwired, the default data type is determined from format string, if format string is a constant. Otherwise, the default data type is a double-precision floating-point numeric control. The default value is 0 or the empty string, depending on the data type.
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 Open 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. If error in indicates that an error occurred before this VI or function ran, error out contains the same error information. Otherwise, it describes the error status that this VI or function produces. Right-click the error out indicator on the front panel and select Explain Error from the shortcut menu for more information about the error.
status is TRUE (X) if an error occurred or FALSE (checkmark) to indicate a warning or that no error occurred.
code is the error or warning code. If status is TRUE, code is a non-zero error code. If status is FALSE, code is 0 or a warning code.
source describes the origin of the error or warning and is, in most cases, the name of the VI or function that produced the error or warning.
output 1..n specifies the output parameters. Each output can be a string path, enumerated type, or any numeric. You cannot use arrays and clusters with this function.

Scan From File Details

Increase the number of parameters by right-clicking the function and selecting Add Parameter from the shortcut menu or by resizing the function.

Note  If an error occurs, the source component of the error out cluster contains a string of the form ''Scan From File (arg n),'' where n is the first argument for which the error occurred.

If you wire a block diagram constant string to format string, LabVIEW checks for errors in format string at compile time. You must correct these errors before you can run the VI. In this case, only Scan failed can occur at run time.

The characters matched by a format string are removed from the file stream. When you use set negation notation, which is used frequently to read an entire string, the matched character(s) are left in the file stream. %[^\n\r] matches an entire line of text, but the carriage return and new line are left behind. To remove these characters, use %[^\n\r]\n\r.

Examples

input stringformat stringdefault(s)output(s)remaining string
abc, xyz
12.3+56i 7200
%3s, %s%f%2dabc00
xyz
0+0i12.3+56i
72
Q+1.27E–3 tailQ%f t1.27E–3ail
0123456789%3d%3d126789
345
X:9.860 Z:3.450X:%fY:%f100 (I32)10Z: 3450
100.0 (DBL)100.0
set49.4.2set%d49.4.2
color: redcolor: %sblue (enum {red, green, blue})red
abcd012xyz3%[a-z]%d
%[a-z]%d
abcd
12
xyz
3
all your base are belong to us, xyzzy_plugh%[^,],%sall your base are belong to us,_plugh
xyzzy