LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

compare a no. in a string ("x") with a no.,y and output booleanT/F when x </> y

I am writing a labview program for the following.

I have to compare two numbers- one of them ('X") is in a string and the other, Y, is a numeric constant and output a boolean TRUE when X is greater than or equal to Y and FALSE for the otehr case. I did this by converting the string to a byte array and using the byte array output as one input of a greater than/ equal to box with the numeric constant as the other input. My sense was that the greater than/equal to box gives out a boolean value which could be used as the toggle that I need. but somehow when I wire the supposedly boolean output from this box to a control switch that needs a boolean T/F toggle- it indicates bad wiring .

can
anyone tell me what the problem is?

thanks
lalitha.
0 Kudos
Message 1 of 14
(3,818 Views)
Hi Lalitha

I did this by converting the string to a byte array and using the byte array output as one input of a greater than/ equal to box with the numeric constant as the other input.

The Problem lies in your above statement. The "Greater than/Equal to" Function has One Input which is array. The Other a Number. The Function Compares each element in the Array to the Number Constant and Builds an Output Array of Booleans. Of Course, When you Connect an array to a Single Indicator you get Bad Wiring. You Can right Click on the Compare Function and Select "Compare Aggregates" to Solve your Wiring Problem. But the Method may not give correct result. Experiment and you will Know.

To address your Problem. I would Use any of "Number to String" Palette Functi
ons available under "String" Functions to Convert the String to a Number ( Double or Integer etc) And then do the Comparison. I would Not use String to Byte Array.

Or Easier for Me is to create a String Constant instead of a Numeric Constant and Do the Comparison Straight. Remember these are Constants on a Diagram. you can put anything in there.

Regards,

Mache
Good Luck!

Mache
0 Kudos
Message 2 of 14
(3,818 Views)
If you compare an array to a scalar or to another array, the output is an array. You cannot compare an array to a scalar and expect to get a single Boolean out. Instead of converting your string to an array, why don't you just convert it to a number by using the Scan from String function. Then your comparison will work as long as your numbers are integers. Comparing equality for floating point numbers is a BAD idea because computers can not represent all floating point numbers exactly in binary.
0 Kudos
Message 3 of 14
(3,818 Views)
I tried doing that - but I am not sure how to give my format string so as to convert the string to a number. how should I use the scan from string function if I need to convert a string to a number?

anyways, I have now input my 2nd number also as a string - that way I am able to compare the two.. but I should like to know how to specify the parameters for scan from string function to get a number from a string.

thanks
Lalitha.
0 Kudos
Message 4 of 14
(3,818 Views)
hi

I get what u r saying. so now Ive input my 2nd number also as a string and the bad wire command has been removed. Now I have another problem. the first number is expressed as say 9.7 E +6 for a value of 9.7 Megaunits. when I compare this with the second no. which I input in the same format I always get a true output regardless of the value of the 2 numbers. is there a specific format in which i enter the 2nd number as a string . ( I input the second no. in a string constant box as *9.8E+3* ). Is this right?

Lalitha.
0 Kudos
Message 5 of 14
(3,818 Views)
HI Lalitha,

I was afraid you would want to Compare real Nos, rather than integers. I believe you are getting your Value from some instrument in exponential notation. The Problem with Exponential notation is it can be represented in many ways and String to String Comparison is a bad idea.

I am Attching a small Example VI, Where I am Converting the String to No and then comparing it to No Constant - three Different Ways. The Obvious Ways of Comparing are Erroneous. The third way is the best. Take a Look.

Check http://www.icon-tech.com.au/faq_frontpanelobjects.html#Comparing



Good Luck

Mache
Good Luck!

Mache
0 Kudos
Message 6 of 14
(3,818 Views)
hi Mache

I could not open the example vi u sent 😞 I got an error saying that resource vi was not found. could it be because im using labview 5.0? could u plz tel me what was done in that example vi for effecting the conversion of string to number.

and ur rite, I am reading the resistance from a DMM and I want the toggle to go to FALSE when the resistance falls below a certain value ( when the resistance shifts from open loop high value to 20 M ohms and second time when it shifts from some Mohms range to approx 1 kohm.) so is htree some way i can convert the no. in the string from the digital indicator of the DMM to a value that I can compare and use?

thanks very much,
Lalitha.
0 Kudos
Message 7 of 14
(3,818 Views)
For a floating point number, the scan string is %f. for integers, use %d. You've also got the function Frac/Exp String to Number that you could use.
0 Kudos
Message 8 of 14
(3,818 Views)
Hi

The Example Vi is in 6.1. I am attaching a Picture of the diagram for you to see.

Mache
Good Luck!

Mache
0 Kudos
Message 9 of 14
(3,818 Views)
I'm attaching a short program that shows how to do this. Take a look at it and see if this is what you're looking for. Just set numbers to either different or similar values, then run the VI, and then LED will light up if they are equal.
J.R. Allen
0 Kudos
Message 10 of 14
(3,672 Views)