LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Assigning Global Variable Values To VI Controls

Hi everyone, I am storing the latest and greatest control data in a global variable.  I want to find a more efficient way to update my VIs control values to what is stored in the global variable.

 

Currently, I am taking each global variable value and writing it to the VIs controls loca variables.  Please see attached.

 

Is there a more efficient way to do this?  If I have a lot of controls this takes up quite a bit of block diagram code space.

 

Thanks!

0 Kudos
Message 1 of 14
(4,348 Views)

Ouch!  Try (really hard) not to use Local Variables -- they are "accidents waiting to happen".  I'm sure very few of us would store the Latest and Greatest Control Data in a Global, and would certainly not put it in a Local.  We would also not call this superlative data "Data 1", 

Message 2 of 14
(4,340 Views)

Oops, hit the wrong key, where was I ...  , Data 2, etc.  

 

The fact that you have 16 "data" values suggests that you might be better off with an Array (if all of the data are essentially the name, like the names of 16 channels) or a Cluster (if they are mixed, and name-able).

 

Where do these data come from?  Are they a Constant, are they read from a file (and hence "fixed for the duration of the program", but "variable from run to run"), can the User modify them at Run Time?  This might impact how you store/save/recall them.

 

Bob Schor

Message 3 of 14
(4,335 Views)

Thanks Bob for the quick response.  I have a VI that needs to pop up twice to an operator duing a test sequence.  It runs the first time and pulls in the boolean values the user entered.  I store these values in a global variable.  So that when it is runs the second time I can populate the controls with the previous entries reading from the global.

0 Kudos
Message 4 of 14
(4,310 Views)

You say boolean but your picture show ints?

 

Anyway, you could create a typedef cluster for your controls. Have a global of this type to store between dialog popups.

 

Assuming you are using a dialog box sort of thing to get the boolean settings from your user, and later present them to him again for info or editing or whatever... use a dialog vi with an event loop for the OK button...

 

Have a control (input) and indicator (output, hidden off screen) of your cluster on your dialog box form, wired to the connector pane. When you call the dialog box you can wire the global to the input connector and it will populate the control cluster. (Leave unwired to use default or previous values). The user can make changes as required. In the 'OK' event (when you close the dialog) wire the control to the indicator to write those values back to your calling routine and store them in your global.

 

cluster dlg bd.pngcluster dlg fp.png

Message 5 of 14
(4,277 Views)

Stuart, just to be clear my typedef global would be a cluster, correct?  I could then pass this global down to the VI cluster input control and then when the OK button was hit pass this to the cluster output indicator and then pass this to my typedef global for storage?

 

PS. Sorry about the int and boolean confusion.  I was only trying to show an example for either or. 

0 Kudos
Message 6 of 14
(4,254 Views)

Yes, that sounds about right. Let me know how it goes.

Message 7 of 14
(4,244 Views)
I don't see the need for a global. You can use a shift register to pass the data into and from the subVI.
Message 8 of 14
(4,225 Views)

Thanks Dennis.  I am trying to pass data into the main VI using a global.  I have a dialog box that prompts the user for boolean input twice.  On the second prompt I want to pull from the global the previous boolean entries in the dialog box prompt.  In this case, I don't think a shift register would work.

0 Kudos
Message 9 of 14
(4,218 Views)
Of course it will work. You set the values in the subVI, pass them out and write to the shift register. The output of the soft register would be wired to the input of the subVI so that the second time it's called, it will use the previous values. You can initialize the shift register to whatever you need to.
Message 10 of 14
(4,212 Views)