LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

case structure question?

chrlum47_0-1617912311515.png

In the above I see how this works for integers....

 

How would it be entered for non-integers?

 

Even if I change the representation two double precision...

 

It still won't allow me to enter non-integers... Is there a special syntax?

0 Kudos
Message 1 of 9
(253 Views)

Hello,

 

Check the help about the Case Structure. I just read the following: "Case selector—Selects which case to execute based on the value of the input data. The input data can be a Boolean, string, integer, enumerated type or error cluster. The data type you wire to the case selector determines the allowed cases you can enter in the selector label."

 

So non-integer are not supported. And if you try to wire a non integer (double below), LabVIEW will coerce its value to an integer (red dot):

caseStructure.png

 

Hope this helps,

 

0 Kudos
Message 2 of 9
(241 Views)

Yes it helps thank you..

0 Kudos
Message 3 of 9
(234 Views)

You may use additional logic, to check the value of a non-integer numeric, using the result of this intermediate logic as input for your case structure. I'm thinking about Comparison Functions and more specifically to In Range and Coerce Function

 

Best regards,

0 Kudos
Message 4 of 9
(225 Views)

As said, floating point numbers can't be directly used.

 

However, if you want, you can get close by approximation, if your floating point numbers are guaranteed to be small enough.  Instead of wiring them in directly, first multiply them by a power of 10 (say, 1000).  Then choose one of the "Round" primitives, to round the number up, down, or to the nearest integer.  Then wire that into the case structure.  Then you can create a case like "2500..2875" that will run for any number that was originally between 2.5 and 2.875.

 

 

Message 5 of 9
(222 Views)

yes thank you all posted answers are very helpful...

0 Kudos
Message 6 of 9
(208 Views)

@Kyle97330 wrote:

As said, floating point numbers can't be directly used.

 

However, if you want, you can get close by approximation, if your floating point numbers are guaranteed to be small enough.  Instead of wiring them in directly, first multiply them by a power of 10 (say, 1000).  Then choose one of the "Round" primitives, to round the number up, down, or to the nearest integer.  Then wire that into the case structure.  Then you can create a case like "2500..2875" that will run for any number that was originally between 2.5 and 2.875.

 

 


Also, while floating point numbers aren't directly supported, they will be coerced to an integer, so you can use a combo of Kyle's suggestion plus this knowledge to get you "close enough".

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 9
(160 Views)

For DBL, you would typically create a 1D array diagram constant containing all range boundaries (unique and sorted), then you would threshold into it with your test value and round down/up to get an integer corresponding to each range. Now you can add a case for multiple, adjacent or nonadjacent ranges as in your first post.

 

(Still you should be aware that all limitations of equal comparisons with DBL values still apply.)

 

Here is an example that uses the integer to index into an array of colors. You can wire it to a case structure instead.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
Message 8 of 9
(106 Views)

excellent this post and the previous... Thank you

0 Kudos
Message 9 of 9
(99 Views)