LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview set case selector condition to range of numerical values

Solved!
Go to solution

Hello, I'm trying to build a case selector with several cases that takes a numeric input and if its value is within 90% of the reference, do case A, if it's within 70% of reference, do case B, etc. The reference changes every loop.

 

So for example, I my reference is 3.3, if I read 2.97 to 3.3, do case A, if I read 2.31 to 2.96, do case B, etc. 

 

I've tried to connect numeric control to case structure, shown on picture, but it only seems to work for integers, if I change those values to decimal, I am getting error. Another issue with this method is that I can only hardcode these values by typing values in case selector, I cannot set it to variables. Same thing with enum cases, you can't set them to variables only to constants as far as I know. 

Screenshot 2023-05-01 120056.png

0 Kudos
Message 1 of 3
(936 Views)

You're correct, when you wire a DBL to the case structure, it gets coerced into an integer, so it's generally not recommended. You could multiply by 100, so your first case would be "297..330", but that's kind of hacky and you might forget when you go to edit the code.

I would use multiple case structures, or select functions (if you just need a single value). You can use "in range and coerce" to check if a value is in a range.

0 Kudos
Message 2 of 3
(926 Views)
Solution
Accepted by topic author John32d

@John32d wrote:

Hello, I'm trying to build a case selector with several cases that takes a numeric input and if its value is within 90% of the reference, do case A, if it's within 70% of reference, do case B, etc. The reference changes every loop.

 

So for example, I my reference is 3.3, if I read 2.97 to 3.3, do case A, if I read 2.31 to 2.96, do case B, etc. 

 

I've tried to connect numeric control to case structure, shown on picture, but it only seems to work for integers, if I change those values to decimal, I am getting error. Another issue with this method is that I can only hardcode these values by typing values in case selector, I cannot set it to variables. Same thing with enum cases, you can't set them to variables only to constants as far as I know. 

Screenshot 2023-05-01 120056.png


Enums are static and cannot be changed at run time.

 

For your case structure, make your reference the variable and have cases for various percentages, like below

 

mcduff_0-1682961380307.png

 

 

 

Message 3 of 3
(922 Views)