LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Minor scan from string bug

But the string you give as an input doesn't contrain any integers, just floats. If you wire an I8 or U8, the input defaults to %d, and you can't use %d to get a "1.000".


I'm not sure if I understand your problem. In the VI you attached earlier (http://forums.ni.com/attachments/ni/170/240365/2/Scan failed.vi), what do you expect as a result?


regards,


Wiebe.
Message 11 of 22
(1,411 Views)

Hi Wiebe,

My question is straight. Won't the Scan from String function give the outputs in the desired formats of integers even though the Inout string is in the format of a float. The context help also suggests the same as what I thought all these days.

In my VI, for the sake of maintaining uniform file writing, we follow the writing pattern of all numeric values in the format of float with 6-digit precision. This happens when you usually bind all your numerics into an array & then convert that array into a spreadsheet string.

So, while reading back the file, I know the order of the Numerics present in that String, meaning whether it is a Dbl or Int or Ring in the UI.

Thats why I tried to scan that string straight away thinking that it'll give Float, Numeric (I8/I16) and Ring (U16) for the corresponding controls in the UI.

Till now, it was perfect in the sense I didnt ve Integers & Rings written consecutively into the file, somehow a Float has got in between each Numeric/Ring in all the UIs except this particular VI. So, when I scan them, they were not giving trouble at all, because the Ring/Numerics were alternately having a Float dat after them.

But this VI has some Numeric & Ring controls in the FP that are written as the first 4 elements of the String with Tab as the delimiter for the file uniformity. Then there are 2 Voltage values (+ve & -ve) written after these 4 Ints into the String.

So, when I read them back, the Scan "FAILED" for the reason that it cannot read the Int correctly because the data in the String were of the type Float like as follows...

1.000000\t2.000000\t3.000000\t4.000000\t5.500000\t6.500000

Can you please try it out with these data & test for me ?

One inportant thing is, don't wire the Format String Input in the Scan from String function.

Even if you specify the Format String input, you ve to specify all the 6 as %f only.

If you specify as %d%d%d%d%f%f, it'll throw you an error.

If you specify as %d%f%d%f%f%f or %f%d%f%d%f%f, then it ll scan correctly.

Please test the attached VI.

- Partha ( CLD until Oct 2024 🙂 )
Message 12 of 22
(1,400 Views)

Hi Partha,

I tried the code that u sent. Actually, if u connect an indicator to the "remaining string" of the scan from string function, u will note that if the data type (%d) does not match the input data type(%f) then the numbers after decimal points are displayed in the remaining string.

I dont know the size of the input string that you read back. But if it the case of reading only the string that u have sent in the code, why dont you try to break the string in two arrays ( first four corresponding to your numeric/ring values and second two for your voltages)

Then you can use "Decimal string to number" and "Fract string to number" to extract the values in indicators.

I dont know how tedious it will be for u.

 

Message 13 of 22
(1,396 Views)


@Harry02 wrote:

I dont know how tedious it will be for u.


Hi Harry,

It is not a question of tediousness. It is not tedious either, what you ve mentioened...

But it is the question of easiness for future implementations, say tomorrow, some more parameters are added in the UI, then you should exercise some sort of uniformity in your writing & reading patterns. You cannot keep track of what parameter of which datatype is written at which location.

- Partha ( CLD until Oct 2024 🙂 )
Message 14 of 22
(1,394 Views)

Hi Partha,

I do agree to the concern for future implemetations. But anyways to use the scan from string function, you would require the exact format of the string that you read from the file.

The only problem starts as i mentioned in my earlier mail, is when you have input data type as float and you format it to integer. You do get the first value but until and unless you dont have the "remaining string" empty other values will not be displayeda as expected.

Pls find the attached image file with the code and the result that i got.

0 Kudos
Message 15 of 22
(1,390 Views)

Hi Partha,

I do agree to the concern for future implemetations. But anyways to use the scan from string function, you would require the exact format of the string that you read from the file.

The only problem starts as i mentioned in my earlier mail, is when you have input data type as float and you format it to integer. You do get the first value but until and unless you dont have the "remaining string" empty other values will not be displayeda as expected.

Pls find the attached image file with the code and the result that i got.

0 Kudos
Message 16 of 22
(1,391 Views)
"But it is the question of easiness for future implementations, say tomorrow, some more parameters are added in the UI, then you should exercise some sort of uniformity in your writing & reading patterns. You cannot keep track of what parameter of which datatype is written at which location."

This sounds like a programmer problem, not something which should be in-build into "scan from string".  Strings, as is their nature, contain a wide multitude of different formats.  If you want to scan numbers which (may) be represented as floats, then scan them as floats and convert them to integers once you have them in numerical format.

Leaving the .0000. un-scanned from string (so to say) is correct behaviour.  If you tell the VI to scan an integer, it will do just that.  If you want other behaviour, you need to tell it what you want (i.e. float).

Shane.

PS another point is that if the data should be an integer, why is the string represented as a float?  Shouldn't the string then be 1\t2\t.....6.500000\t and so on.

Message Edited by shoneill on 04-11-2007 11:38 AM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 17 of 22
(1,385 Views)

Hi,

I think partha has made it clear in his earlier comments that the values are stored as float in the file with a precesion of 6.

So the string which is read from the file will have 1.000000\t....6.500000 etc and not 1\t...6.500000.

Also what one can do is simply input the format type to %f%f%f..and so on and then may be connect each of them to display as either integer ao float. We can always change the display of the indicator as we desire.

Any comments?

0 Kudos
Message 18 of 22
(1,381 Views)
I understood that fact, but my question was more if Partha had any influence over the creation of the string.  He made comments about adaptability, so I assumed he would have some element of control over the string composition.  In that case, it's a valid question why the string representation of an integer should be stored as a float......

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 19 of 22
(1,376 Views)


 


@shoneill wrote:
it's a valid question why the string representation of an integer should be stored as a float......
Shane.


Shane,

It is for the uniformity of File writing that we follow the procedure of converting all the Numeric values ( Dbl/Int/Ring ) to be of Float String with 6 digit precision. This is because all our rest sub-VIs (UIs) that show the variouus settings for different cards have more no. of parameters that in turn are of the nature Dbl, like Voltages, Clamp Currents, Sine/Ramp Voltage values, etc.

So, they need to be written in Dbl Str format, right... ?!

Our team follows the same procedure of building them into arrays & converting them into Dbl Str arrays.

These settings for the various cards are in turn shown in the Table in the FP & converted into a Spreadsheet Str on a single stroke, and written in a txt file without extension so that it can be opened either in Notepad/Wordpad as per availability for reference.

Thats why all my confusion with the Scan from String function, if that was a minor bug...

Now I'm clear about it.

Thank you all !

- Partha ( CLD until Oct 2024 🙂 )
Message 20 of 22
(1,369 Views)