LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

can I use variables in case structure range?

Let's say I have a case structure that switches on a number.  Obviously I can define a range for a given case, i.e. 0..4, 5..8, 9..100.

 

But what if I want those ranges defined by variables?  i.e.

MIN_A = 0

MAX_A = 4

MIN_B = 5

MAX_B = 8

MIN_C = 9

MAX_C = 100

 

is there a way to create a case structure to where I can enter those variables as the range?

 

I know an alternative woulud be to simply compare the number to those ranges and switch on true-false and nest the case structures, but didn't know if I could do it directly as described above.

0 Kudos
Message 1 of 8
(3,240 Views)

Wow, that's a good question!  It seems like a very useful feature though.  Of course it begs the question of what happens if conflicting ranges are entered during run-time.  Smiley Frustrated

 

Now I'm curious as to what some of the LabVIEW gurus around here are going to say about it...

LabVIEW Pro Dev & Measurement Studio Pro (VS Pro) 2019 - Unfortunately now moving back to C#, .NET, Python due to forced change to subscription model by NI. 8^{
0 Kudos
Message 2 of 8
(3,234 Views)

Hi,

 

put those numbers in an array and use Interpolate1DArray to find the corresponding range!

It takes care of overlapping ranges - somehow… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 8
(3,229 Views)

This is interesting question.

I think you could wire in your min and max variables to couple of 'In Range and Coerce' functions, and based on the outcome generate an enum value for example. Then you can use that enum wired in to a case structure.

 

 

Message 4 of 8
(3,223 Views)

GerdW wrote:

put those numbers in an array and use Interpolate1DArray to find the corresponding range!

It takes care of overlapping ranges - somehow… 😄


I think what you really want is Threshold 1D Array.  That will give the "index" of the value you give it.  It does assume a constantly rising array, but that shouldn't be much of an issue.  Then you just put this index into the case selector.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 8
(3,201 Views)

I'd go for 3 In range and Coerce, and an AND to combine them. Maybe there's a slimmer way.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 6 of 8
(3,160 Views)

@Yamaeda wrote:

I'd go for 3 In range and Coerce, and an AND to combine them. Maybe there's a slimmer way.

/Y


Why the AND?  Or do you mean Build Array and then Boolean Array to Number?


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 8
(3,146 Views)

@crossrulz wrote:

@Yamaeda wrote:

I'd go for 3 In range and Coerce, and an AND to combine them. Maybe there's a slimmer way.

/Y


Why the AND?  Or do you mean Build Array and then Boolean Array to Number?


Unless i misunderstood, there are 3 different variables that needs to be in range, bool array to number would also be a solution if the other combinations are of interest.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 8 of 8
(3,129 Views)