LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Interesting scan from string error

Got an interesting (and hopefully easy) issue with scan from string. VI and back panel image attached. Open it or make it and try to run it and let me know if you get an error too. Am I doing anything wrong?
 
(BTW, ignore the %d in the scan from string. You can change those to %f or %g and it still burps)


Message Edited by mlang on 07-21-2008 09:04 AM
Download All
Message 1 of 7
(2,968 Views)
You must not use commas as delimiter in the formatstring but you have to use blanks.
So your formatstring should read "%s %f %f %f" instead of "%s,%d,%d,%d" as it currently does....

hope this helps,
Norbert
Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 7
(2,955 Views)
This is normal behaviour. The function tries to scan the string, and the
entire input is scanned. Next, it tries to parse ",%d", which will fail
because the rest of the string is empty.

Try "%[^,],%d,%d,%d". %[^,] scans all characters that are not ",".

Regards,

Wiebe.


0 Kudos
Message 3 of 7
(2,941 Views)


Wiebe@CARYA a écrit:

Try "%[^,],%d,%d,%d". %[^,] scans all characters that are not ",".


With this unique format specifier for Format Into String and Scan from String, an error will appear if the input string contains a comma or is empty (the last case is also true with the original code). Distinct specifiers may be needed to avoid this.
0 Kudos
Message 4 of 7
(2,933 Views)

"JB" <x@no.email> wrote in message
news:1216654807531-747929@exchange.ni.com...
> Wiebe@CARYA a écrit:
> Try "%[^,],%d,%d,%d". %[^,] scans all characters that are not ",".With
this unique format specifier for Format Into String and Scan from String, an
error will appear if the input string contains a comma or is empty (the last
case is also true with the original code). Distinct specifiers may be needed
to avoid this.

Yes, comma's might not be the best seperator. It will also fail if the
numbers use "," as seperators (as is often the case in Europe)...

But the same can be said for any seprator... If you use tabs as seperator,
the parsing will fail if the string contains tabs...

Regards,

Wiebe.



0 Kudos
Message 5 of 7
(2,919 Views)
Interesting that commas mess the scan up. Though that European period/comma duality does make a convincing argument against using commas as a delimiter. Too bad my input is a .csv with some text to make things complicated. There's no other commas other than the delimiters so I can go through and just replace them all w/ tabs or some such before scanning it.

Thanks!
0 Kudos
Message 6 of 7
(2,890 Views)
Here is an idea... Use the Spreadsheet Strnig to Array. Use , as seperator,
and %s as format. Then you'll get a 2d array of strings. Remove the first
column and you get all your strings. Convert the rest with a Decimal String
To Number, and you're done!

As for comma as decimal point problem... The format into string and scan
from string both understand the %.; operator. This makes them use points as
seperator. Also, LabVIEW has some ini file settings that make LabVIEW use
points i.s.o. comma's. It's usually not a problem (even if you have to use
comma's, for instance with SQL queries), except that once in a while you
forget about it...

Regards,

Wiebe.


0 Kudos
Message 7 of 7
(2,875 Views)