Scan From File Function

LabVIEW 2018 Help

Edition Date: March 2018
Part Number: 371361R-01
View Product Info

DOWNLOAD (Windows Only)

LabVIEW 2016 Help
LabVIEW 2017 Help
LabVIEW 2018 Help
LabVIEW 2019 Help
LabVIEW 2020 Help

Owning Palette: File I/O VIs and Functions

Requires: Base Development System

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. This function does not work for files inside an LLB.

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 from Text File function and the Scan From String function.

Details  Example

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.

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.
default 1..n specifies the type and default value for the output parameters. If this function cannot scan the input value from format string, the function uses the default. If you do not wire default 1 and you wire a constant to format string, the function uses format string to determine the type of the output. Otherwise, the default data type is double-precision, floating-point. The default value is 0 or an empty string, depending on the output data type. If you wire an enumerated type to default 1, the function finds substrings matching the string values in the enumerated type and returns the corresponding numeric value of the enumerated type.

You can scan for Boolean values if you use a string or numeric format code. If the format code is %s or unwired, the function reads Y, T, TRUE, ON, or YES and any lowercase versions of those words as TRUE Boolean values. The function reads F, FALSE, OFF, or NO and any lowercase versions of those words as FALSE Boolean values. If you specify a numeric format code, the function reads any numeric value greater than 0.5 as TRUE and any numeric value less than or equal to 0.5 as FALSE.
Note  This function reads negative numbers as FALSE Boolean values because the function converts the number to an unsigned 8-bit integer and any number less than or equal to 0.5 becomes 0 during the conversion.
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.
output 1..n specifies the output parameters. Each output can be a string, path, enumerated type, time stamp, Boolean, or any numeric data type. If you scan a string that does not fit into the numeric data type you specify, this function returns the largest number that fits into that data type. 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 uses format string to determine the number of outputs and the data type of each output at compile time. If the types you wire to the outputs do not match the types determined by format string, you must change the output types before the VI can run.

If you do not directly wire a block diagram constant to format string, LabVIEW checks for type mismatches at run time. If you want to scan values that have data types other than double-precision, floating point, you must wire the data types to default 1..n.

When you use the match characters not in set format specifier (%[^...]), 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.

Note  By default, this function is locale aware, which means that it uses the system decimal separator configured in the regional settings of the operating system. In some instances, such as using GPIB instruments on European operating systems, you may need to override the system decimal separator by using the localization code syntax elements.

Examples of Formatting Strings

input stringformat stringdefault(s)output(s)remaining string
abc, xyz
12.3+56i 7200
%3s, %s%f%2dabc00
Q+1.27E–3 tailQ%f t1.27E–3ail
X:9.860 Z:3.450X:%fY:%f100 (I32)10Z: 3450
100.00 (DBL)100.00
color: redcolor: %sblue (enum {red, green, blue})red
welcome to LabVIEW, John Smith%[^,],%swelcome to LabVIEWSmith


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 Scan From File function.


Not Helpful