LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Avoiding two while loops

Hi together,

 

I'm trying to fit these two while loops into the programm(see attached vi) now ive got the problem that i need to stop the inner loop to change the input value. Can someone tell me which other ways there are to get where i want to get?

0 Kudos
Message 1 of 6
(3,013 Views)

Hi WZL,

 

get rid of the inner loop…

 

Simplified:

check.png

(Change the "1" button to "switch" instead of "latch"…)

 

Did you notice those "Training resources" in the header of the LabVIEW board? It seems you can learn from them…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 6
(3,003 Views)

Thank you very much! Gonna try it!

0 Kudos
Message 3 of 6
(3,000 Views)

I cant use the "select" mode, if i want to add more buttons for different values, right?

0 Kudos
Message 4 of 6
(2,990 Views)

Hi WZL,

 


@WZL_94 wrote:

I cant use the "select" mode, if i want to add more buttons for different values, right?


Well, you could use more than one Select node…

 

To keep the code clean and scalable there are other methods:

  • Use a radiobutton to select between several options!
  • Use a button array and analyze which button was switched (last).
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 6
(2,974 Views)

Another thing you could do to select one of a (small) finite set is to use an "enum" (short for "Enumerated Something-or-other").  For example, suppose you wanted to select a Color from the list "Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet".  On the Front Panel, you could "drop" an Enum (from "Ring and Enum" Palette), call it "Color", right-click and edit it and assign it those seven "human-understandable" values (i.e. "Red", etc.).  When you are done, you'll see that you have a Control that can take on those seven (and only those seven) values.  Behind the scenes, LabVIEW represents them as U16 (I think, but it doesn't matter), but in dealing with you, they are color names.

 

Guess what happens if you put Color in a Value-changed Event, and you change the color?  The Event fires, and you get the current color.  What if you take Color and increment it?  If it was Green, you get Blue.  If it was Violet, you get the "next" color, which is "Red".  This makes it easy to write a While loop to "loop" through the colors one at a time, like this:

Color Enum to Array of ColorColor Enum to Array of Color

 

This takes the Color Enum (which has who-knows-how-many-values) and enumerates them one at a time, outputting the values into a Color Array.  We use the first color presented (which might not be the first color of the Enum, i.e. it might be "Green", not "Red") and keep looping until the "next" color matches the first, which means we are done.

 

I attached a LabVIEW 2017 version.

 

Bob Schor 

 

Message 6 of 6
(2,959 Views)