LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple local variable for one single controller?

Hello everyone, I am a new in Labview. Here is a simple question for using local variable in labview, and I wonder may I create multiple local variables for only one controller or indicator?

 

My case is that the controller needs to be at the same time the one which can be read and also updated and written in if we press different buttons.

 

If so, how to control the data flow sequence?

 

Enjoy your day and looking forwards to your kind reply!

 

Best Regards,

 

Fei

0 Kudos
Message 1 of 4
(3,176 Views)

You can have multiple locals for the same control, but you need to be very careful about creating race conditions. If the update of the local is done only at specific points in time in response to user interaction, then you should usually be fine. Assuming you use an event structure to process the UI events from the control, you can usually update the control with safety in other cases of that event structure (in response to the other things the user does in the UI).

 

I should note that I'm assuming that you're only using the control as a UI control, not as a variable. I know that NI gave them the name local variables and that they work similarly to variables in other languages, but generally, you should not use controls and indicators as variables. It works, but you run the risk of race conditions. Instead, you use wires to move the data from function to function.

 

What I described in the first paragraph is only one way of doing things. Often, if you have a more complex piece of code it's usually better to keep the actual current values not in the UI, but in a separate place where you can always make sure they are all synchronized (such as a cluster of state data in a shift register). Then you ignore the value in the control and only update from it when it is changed by the user.

 

There's quite a lot of material around, but I suggest you start by looking at some of these tutorials.

 

 


___________________
Try to take over the world!
0 Kudos
Message 2 of 4
(3,160 Views)

Thx quite much!

 

Actually, I need to use the controllers at the same time as input parameters, variables and indicators. For example, for one controller A, if I press button 1, it will be used as a input for the following calculation and the results will be transfered to some other controllers.  Then after pressing another button 2, the value of controller A will be recalculated and updated based on the results from button 1; Meanwhile, there is the 3rd button, button 3, which run the operation in an another methods to calculate the shifting value of the controller A by other controllersand controller A's current value; then press button 2 again, the current controller A's value will be updated again.

 

I am sorry it is a little bit complicated to describe, and I hope that I have make it clear.

 

Best Regards!

0 Kudos
Message 3 of 4
(3,156 Views)

@sophiey wrote:
I hope that I have make it clear.

Not really, but it sounds like it could work. I suggest you build it and see how it behaves.


___________________
Try to take over the world!
0 Kudos
Message 4 of 4
(3,147 Views)