LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

help with error on file i/o vi....

Solved!
Go to solution

i am getting an error messege that reads, "Scan failed. The input string does not contain data in the expected format." when i scan from file....

write.png

read.png

is it my "format string" on the "scan from file vi"? should i just format "read from spreadsheet file" string output to their necessary formats...

0 Kudos
Message 1 of 10
(3,448 Views)

You are adding commas as delimiters between fields with an EOL at the end of each block yet when you read you use the comma as a delimiter on the Read From Spreadsheet File.  You end up with way more iterations than data.  Use a new line character as your delimiter.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 2 of 10
(3,434 Views)

Why are you using %u as a format code?

 

According to the help, it is "fractional seconds with <digit> precision".  You certainly don't have that with your U32 integer.

0 Kudos
Message 3 of 10
(3,420 Views)

RavensFan is correct, you should use %d.  Right click on the Format Into File and select Edit Format String.  That will help you get your format string correct.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 4 of 10
(3,410 Views)

@kbbersch wrote:

RavensFan is correct, you should use %d.  Right click on the Format Into File and select Edit Format String.  That will help you get your format string correct.

 


applied the correction with the %d....no change in error, but lessen the read of the format string input to "%d,%d,%d,%.3f,%.3f" and NO ERRORS!

so it is how i read the combo string controls by using "%s". maybe not reading the full string "5V upper lamps/ 5V lower lamps" with just "%s" format. any suggestion on reading this full string and what format to use?

0 Kudos
Message 5 of 10
(3,398 Views)

A little trick to make your code a little simpler and memory efficient...

 

Use the Read From Text File function.  Right-click on it and select "Read Lines".  Yes, you can configure it to read X lines.  Set the count to -1 to read all of the lines.  You can then pass that array into the FOR loop and use the Scan From String instead of the Scan From File.  This will result in you not reading the entire file twice.

 

 

Also, if you are trying to scan out strings, you should use "%[^,]".  That will give you every character up to, but not including, a comma.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 10
(3,394 Views)

For your scan from string format code try %[ /-9A-Za-z] (there is a space character between the [ and /).  I think I got all the characters you're using.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 7 of 10
(3,383 Views)
Solution
Accepted by topic author apok

@kbbersch wrote:

For your scan from string format code try %[ /-9A-Za-z] (there is a space character between the [ and /).  I think I got all the characters you're using.

 


By using %[^,] you don't need to figure out every possible character.  It just grabs anything until the comma.  Very useful when dealing with delimited data like this.

 

Apok, I highly suggesting looking in the LabVIEW help for Format Specifier Syntax.  It will make things a lot more clear for how to use that format string.  I actually have this hanging in my office because I reference it so often.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 10
(3,361 Views)

@crossrulz wrote:

@kbbersch wrote:

For your scan from string format code try %[ /-9A-Za-z] (there is a space character between the [ and /).  I think I got all the characters you're using.

 


By using %[^,] you don't need to figure out every possible character.  It just grabs anything until the comma.  Very useful when dealing with delimited data like this.

 

Apok, I highly suggesting looking in the LabVIEW help for Format Specifier Syntax.  It will make things a lot more clear for how to use that format string.  I actually have this hanging in my office because I reference it so often.


Yep, and I missed that in your first reply.

 

I used to have a copy of that hanging on the wall as well.  It's time to make another one.

 

Kelly Bersch
Certified LabVIEW Developer
Kudos are always welcome
0 Kudos
Message 9 of 10
(3,350 Views)

thanks crossrulz...the input final string format that worked, "%d,%d,%d,%.3f,%.3f,%[^,],%[^]\n"

 

only other option (maybe not the only solution) was to go integer wise with "enums"

0 Kudos
Message 10 of 10
(3,313 Views)