LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Trouble with 'if...else' statement

I am trying to excute a 'if...else' statement with a case structure, but I am having some trouble.
I am reading in an input value (represents current). If it is higher then 'x' then I want to execute case 1, if its lower than 'y' then I want to execute 2, and if it is in between then I want to execute case 3. Can anyone help me out with this.

Thanks in advance.
0 Kudos
Message 1 of 6
(3,618 Views)
See attached vi. If using integers, use the top case. If using floating points, use the bottom case.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 6
(3,618 Views)
Hi

My solution might be a little heavy but I would do it that way.
Use 3 comparisons vi (Less, Equal and Greater) and connect on each of them a
constant. Constants that are in relation with your input values.
Then, use 3 case structures to which the comparisons vi will be connected.
In the first case structure put a numeric constant =zero in the true case
Do the same with the 2 others. Put in the second one a constant =0ne and in
the last one a constant =two
Connect each output of the constants (zero, one and two) in a compound
arithmetic. Use then the output of the compound to wire it to the input of a
case structure. But this time, you'll have three cases at your disposal.

Good luck

Gérard



--
Gérard Férini
Switzerland
http://home.tiscalinet.ch/gferini/Main_
Photos.html
http://www.pbase.com/ferini
remove -move to reply
ferini@move-bluewin.ch
"trigeek" wrote in message
news:5065000000080000002BFE0000-1079395200000@exchange.ni.com...
I am trying to excute a 'if...else' statement with a case structure,
but I am having some trouble.
I am reading in an input value (represents current). If it is higher
then 'x' then I want to execute case 1, if its lower than 'y' then I
want to execute 2, and if it is in between then I want to execute case
3. Can anyone help me out with this.

Thanks in advance.
0 Kudos
Message 3 of 6
(3,618 Views)
trigeek wrote in news:5065000000080000002BFE0000-
1079395200000@exchange.ni.com:

> I am trying to excute a 'if...else' statement with a case structure,
> but I am having some trouble.
> I am reading in an input value (represents current). If it is higher
> then 'x' then I want to execute case 1, if its lower than 'y' then I
> want to execute 2, and if it is in between then I want to execute case
> 3. Can anyone help me out with this.

You can use ranges with the Case structure

Example if the numbers are integers:
Selector Description
Case one ..5 All values up to 5
Case two 6..10 All values from 6 to 10
Case three 11.. All values from 11 and up
or Case three Default All other values

You also
have range when using strings.
Case one selector is "ABC".."ABE" (from ABC up to, but not including, ABE)
Case two selector is "ABE".."AZ"
Case three selector is Default
Case one will execute when string is ABC, ABCAAAAAA or ABDZZZZZZZ
Case two will execute when string is ABE, AYYYYYYYY
Case three will execute when string is AZ

If it is a decimal number i could suggest to use an array with the limits
in and use the "Search 1D array" to get indicies and connect the indicies
to the case selector.

--
Rolf
0 Kudos
Message 4 of 6
(3,618 Views)
I can't open your vi since I only have LabVIEW 7.0. If you could save a screen shot I would greatly appreciate it, or back save your vi to 7.0.

Thanks a ton,
Travis
0 Kudos
Message 5 of 6
(3,618 Views)
I saved tbob's compare.vi in version 7.0 of LabVIEW, so you should be able to open it now. I called it case structure.vi
0 Kudos
Message 6 of 6
(3,618 Views)