LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

numeric indicator and control at same time

I have created a simple demo, see enclosed file.  I have numeric control connected to scroll bar. From the numeric control is controlled scroll bar and vice versa. If I connect second numeric control (Numeric 2) to scroll bar, I see the value of scroll bar, but from Numeric 2, I cannot control scroll bar and Numeric 1.

Please help advice, where is mistake?

Download All
0 Kudos
Message 1 of 4
(2,615 Views)

You are forgetting (or haven't learned) the most important LabVIEW concept, the Principle of Data Flow.  Among other things, it says that a Structure (such as a While Loop) can't finish executing until everything inside it has executed.  Your While Loop contains an Event Structure, which doesn't execute until an Event occurs.  The only thing that makes this Event Structure "fire" is changing Numeric (an extremely "sloppy" name to choose -- always give your Variables meaningful names, don't be lazy and accept the default). 

 

Try this -- create an Indicator, call it "Value of Num 2", and wire it to the Numeric 2 control.  It should "track" Numeric 2, right?  Run your code.  When you change Numeric, everything else (including Value of Num 2) changes.  But when you change Numeric 2, Value of Num 2 remains the same.  Do you know why?  Remember the Principle of Data Flow, and ask yourself "When did Value of Num 2 get set, particularly in relationship to when Numeric 2 changed".

 

Bob Schor 

0 Kudos
Message 2 of 4
(2,595 Views)

Bob, thank you.

0 Kudos
Message 3 of 4
(2,580 Views)

In addition to what Bob already said:

  • Never use value properties for any of this, local variables are the correct tool to update a control programmatically.
  • To read from a control, wire to the terminal directly.
  • Usually one control per function is sufficient. Why do you need three for the same thing?
  • Once the control value has changed (via any of the three controls), you probably want to do something with the synchronized value, right?
  • You need something to stop the VI.
  • You don't need the timeout event here.

Here's a quick modification that hopefully gives you some ideas. I took the terminals outside the loop because we only read the value from the event data node. In more complicated code, place them where they are used.

There is no need to micromanage which control has changed and what needs to be updated using tons of complicated code. Just write back to all. Also note that since a scrollbar can generate many value changes as it is operated, I limited the event queue to 1.

 

syncvaluesfromcontrols.png

0 Kudos
Message 4 of 4
(2,548 Views)