LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using local variables with a case structure

I recently decided that I didn't want to nest a bunch of case structures for a program I am creating. I have two variables, N1 and N2, and I want to say execute Case 1 if the integer input to the terminal is less than N2. Case 2 if the integer input into the terminal is greater than N2 but less than N2+N1. Case 3, integer greater than N2 + N1, but less than N2+N1+N2. Case 4, you guessed it, Greater than N2+N1+N2, but less than N2+N1+N2+N1. When I try to type the variable name into the bar and use the ... like you do with integers it changes the variable name to a string.
Am I just thinking of this the wrong way? I have a sensor setup in a square and I am using a matrix card hooked up to the sensor bundle to send signals from each sensor to each other sensor, but not for those along the same sides.

Tom
0 Kudos
Message 1 of 6
(6,211 Views)

Hello Tom.

I think our code sounds like a candidate for a Formula Node.
LabVIEW comes with examples on how to use them.

Regards, Guenter

0 Kudos
Message 2 of 6
(6,204 Views)

You can't use local variables or controls or indicators as the Case selection value.  Case values must be strings, enums, True/False, or numeric values.  You could test each condition and assign some number to it depending on the outcome, then use the number for a case selector.  But this sounds very awkward as shown in the attached vi.  Even a formula node would get awkward with all the greater thans and less thans.

 

- tbob

Inventor of the WORM Global
Message 3 of 6
(6,202 Views)
This is becoming quite interesting. I know exactly how to program it in Visual Basic, or C++. I could probably do it in MATLAB also, but i don't like using one programming language inside another like LabVIEW lets you, and more importantly the man who signs the checks hates it.  The predicament still stands. I will try and upload the VI and a visual of what I am trying to do tomorrow.

Tom


0 Kudos
Message 4 of 6
(6,195 Views)
In VB or C you would use a nested If-Else structure.  Here is the same in Labview using nested Case structures.
 
- tbob

Inventor of the WORM Global
Message 5 of 6
(6,186 Views)
I see the nested case structures which is what I didn't want to do, but I will have to because I am tired of looking at this. Thank you for the help on this. I appreciate it.
The sensor network is shown in the image included.  Lets say we number the sensors in a clockwise direction starting on the lower left hand corner. Each element needs to both send and recieve data to all other elements except for the one in the row it is in. So sensor 1 would sent to sensor to sensors 5 - 18. Then sensor 2 would send to 5 - 18. Sensor 5 would sent to 1 - 4 and 10 - 18. Etc.

Lets say if this were a circular array it would be easy. Two nested while loops. And the only condition I need to worry about is that sensor N is not both sending and recieving at the same time. Each while loop, or for loop - doesn't matter, will start at 0 and go to N-1. Each i and j will have +1 added to them, and as long as they are not equal preform the data operation. 

Just some fun logic to think about

Tom

0 Kudos
Message 6 of 6
(6,176 Views)