From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to associate existing global variables

Solved!
Go to solution

This is probably something silly that I'm missing.

 

I created a global variable and made it a string.  I put it in a file called XML_Global.vi  I then proceeded to make another global var and was going to assign it to the same variable.  However, the IDE shows me another Globals 4 Front Panel.  How can I associate the existing XML_Global.vi front panel with the global variable that I plopped down there?  I looked all over how to do this in Properties and such, but couldn't find it.

0 Kudos
Message 1 of 8
(5,407 Views)
To be honest I am not sure how to fix your particular issue. The reason for this is that I don't use global variables and my advice to you would be to avoid using them as well. Use data flow (the wire itself), queues or action engines (functional globals) instead. A design that relies heavily on global variables generally is not as robust or as flexible as other designs. In addition, they can be challenging to debug and may run into timing issues.


Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 8
(5,402 Views)
Solution
Accepted by topic author RS_233

Have you read through this document?

 

http://zone.ni.com/reference/en-XX/help/371361F-01/lvhowto/creating_global_variables/

 

There may be some confusion as to what is happening...When I add a global variable to the block diagram the rough process I follow is to:

  • Open the front panel for the global variable
  • Add FP items (there can be multiple items in a global variable VI)
  • Save the global variable VI
  • Then drag+drop from my project to a VI block diagram
  • Select the variable I want by right-clicking the Global and going to Select Item > Variable name

 

Does this clear everything up for you? It sounds like you're trying to simply place another global variable instance from the functions palette, and then select the variable to assign this instance to (similar to what you would do with a local variable)? With globals, a new instance of a global VI is created when you drop the BD global...you're going to want to place the global you edited/saved (drag+drop from project or use the 'Select a VI' from the functions palette).

 

Hope this helps...

 

Message 3 of 8
(5,396 Views)

Mark, the reason for using globals would be to turn an array of strings into one string.  I was going to make a for-loop, in there would be a global from which info is read and then concatenated to an input string (which is iterated through, since that would be the array of string) and the results stored in the same global variable (effectively over-writing the previous results.)

 

The reason for choosing globals would be to figure out how to force the VI to use the one and only global Front Panel that I have stored in my development directory.

 

I'd post the code, but my employer prohibits it.

0 Kudos
Message 4 of 8
(5,395 Views)
Must've missed that article.  Thanks BOB.
0 Kudos
Message 5 of 8
(5,385 Views)

RS_233 wrote:

Mark, the reason for using globals would be to turn an array of strings into one string.  I was going to make a for-loop, in there would be a global from which info is read and then concatenated to an input string (which is iterated through, since that would be the array of string) and the results stored in the same global variable (effectively over-writing the previous results.)

 

The reason for choosing globals would be to figure out how to force the VI to use the one and only global Front Panel that I have stored in my development directory.

 

I'd post the code, but my employer prohibits it.


I would still avoid using globals. The methods I suggested above are better ways of achieving the same functionality. Specifically, the action engine seems like it would be a verygood candidate for your task. Applications that rely on globals tend to be difficult to maintain over time. You have very little way of knowing what will be affected when you change the global. In addition, you don't have a good way of preventing side effects from occuring since you don't really control the access to the data.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 6 of 8
(5,378 Views)
What is an "action engine"?  I googled it and found a few examples, but was hoping to find an actual working VI that I can dig into.  Do you happen to know of an example?
0 Kudos
Message 7 of 8
(5,346 Views)

RS_233 wrote:
What is an "action engine"?  I googled it and found a few examples, but was hoping to find an actual working VI that I can dig into.  Do you happen to know of an example?

 

I wrote a Nugget about Action Engines that can be found here.

 

They are a code construct that allows sharing data between threads with built-in mutexes. They are prefered over Global Varialbes because the multithreaded nature of LV permits race-conditions when accessing shared data structures without explicit proction via semaphores etc.

 

Or in simler language...

 

They are a Global Variable that is immune* to race conditions.

 

Ben

 

* The immunity only applies if they are coded and used properly.

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 8 of 8
(5,337 Views)