LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Scan From File works only on first line

Solved!
Go to solution

Hi

 

I'm new to Labview (ver 8.6) and I'm running into this problem.

I'm using Scan From File to get a number of setup information from test.txt.  The data in the file looks like this:

AAA 1

BBB 2

CCC 3

I've noticed that the Scan From File works for only the first line.  Attempting to get data that is not in the first line results in an Error 85.

Any Ideas? Thanks

 

 

0 Kudos
Message 1 of 5
(3,072 Views)

"e:\scanfile.png"  is sadly no webpublished filepath.

Please post the image first and then insert it into you post.

 

thanks,
Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 5
(3,065 Views)
Sorry, I'm new to posting also
0 Kudos
Message 3 of 5
(3,054 Views)

The error is expected.

Please note the help to the function you use:

Use this function when you know the exact format of the input.

In your example, the first time the input starts with AAA, so "AAA %s" as formatstring fits the first part of your input.

But you remove AAA 1 from the string, leaving a new line command before BBB.

So your string looks like:

"

BBB 2"

Therefore, it does not start with BBB and the second function will create the error.

 

If you can't remove the new line command, you can either load the whole file and parse it using "Scan from String" and configuring a correct offset for each call, or you have to work with other functions like "Match Pattern".

 

hope this helps,
Norbert

 

 

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 4 of 5
(3,035 Views)
Solution
Accepted by topic author scorpsword

It's all in what the scan from file reads, and what the next cgaracter in the file is.

 

Your first scan from file will read up to but NOT including the first newline in the file.

The second read reads from where the first read left off, and expects to see "B" as the next character, but instead sees the new line, and so the scan fails. You need to tell the second formatted read to expect the newline.

 

You can do this by making the FIRST character of the format string a space, which will tell it to expect any number of "white space" charaters.

 

Yo can in fact put a space at the beginning of the  format string in your first scan from file and it will match with zero white space characters before seeing the AAA. By doing this it is also tolerant of seeing spaces and tabs before your AAA or BBB identifiers.

 

Rod.

 

Message 5 of 5
(3,030 Views)