Detect End of File When Using Scan from File or Scan from String Functions

Updated Jan 3, 2018

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full
  • LabVIEW Professional

Issue Details

I'm trying to use the Scan From File or the Scan From String functions to read a file of an unknown length.  When the scan gets to the end of the file, I receive Error 85: "LabVIEW: Scan failed. The input string does not contain data in the expected format."  How do I stop a scan when I get to the end of a file without getting an error?

Solution

The Scan From File and Scan From String functions do not return a unique error code when an end of file is reached while scanning in a while loop.  Two methods for programmatically stopping a scan are shown here: 

Method 1
  1. Use the Read From File function to read the entire file.  The file is output as a string.
  2. In a while loop, use the Scan from String function to parse the string.  
  3. Check whether or not the remaining string being scanned is empty.  If the remaining string is empty, do not continue the scan.
  4. Use shift registers to pass the remaining string for the next iteration.

Method 2
  1. Use Get File Size to discover the number of bytes in a file.
  2. Use Scan from File to scan each word out of the file.
  3. Find the size of the word by using the String Length VI, add this to the number of bytes read.
  4. Test to see if the number of bytes read is equal to the size of the file.  Stop scanning once the total number of bytes has been read.

 

WAS THIS ARTICLE HELPFUL?

Not Helpful