LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I programmatically create and use a global variable?

Hey if it's impossible, then why not simply say that instead of saying "I refuse to help"?  And I am accepting ideas to solve the problem -- the USR approach is one I've used before and as ugly as it is, I agree that it will work.  I was just hoping there was a simpler way of doing this since I need a global variable and the global variable construct in LV is far simpler to use than a USR/functional global/action engine.

 

0 Kudos
Message 11 of 27
(3,528 Views)
See my comment earlier, easier is not necessarily better. There are a ton of good reasons to avoid using global variables. The suggestions given offer a better, more robust design which in the long run will minimize the issues you see with your application as well as be easier to extend your application in the future. Learning better ways to do things will ALWAYS pay off for you in the long run.


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 12 of 27
(3,516 Views)

Then there still is the array approach - one global (with just one name) to rule them all to hold all the values...

 

Oh, just forgot: you create serious race conditions when accessing the same global array from several places. Did I mention a FGV before?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 13 of 27
(3,508 Views)

boostinallovryou wrote:
I have to agree, Ben was the unprofessional one.  "I refuse to help anyone use global variables..." 
Message Edited by boostinallovryou on 10-09-2009 12:47 PM
Message Edited by Support on 10-09-2009 01:11 PM

 

Ok it time for me to "take it like a man".

 

I apologize for the wording I used in the earlier post.

 

My intent was and still is to help LabVIEW users to learn and grow. One of the biggest barriers in learning a new language is trying to do so with inconsistant behaviour which is what we have when Global varibles are used in a multithreaded environment without extra code to protect (mutexes) the shared resource (global variable). I feel that I would be doing harm to the person asking, if I aid them in using Globals and the same time fail to offer a viable alternative.

 

I wrote that Nugget for that very purpose. I hope that you will still read that Nugget in the hopes that it can still help you!

 

Ben

 

PS: Thanks for the back-up gang!

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 14 of 27
(3,491 Views)

boostinallovryou wrote:
I have to agree, Ben was the unprofessional one.  "I refuse to help anyone use global variables..." 

 

I have to side with Ben.

 

Friends don't let friends drive drunk.

 

And friends don't let friends use global variables.

 

PaulG.

LabVIEW versions 5.0 - 2023

“All programmers are optimists”
― Frederick P. Brooks Jr.
Message 15 of 27
(3,489 Views)

Ah.  I understand the source of the flames.  I thought you were implying all global variables were bad, when it now sounds like you were saying that LabView's implementation of global variables is dangerous (no mutexes) -- never mind it's impossible to do what I wanted.  That makes this whole forum thread make more sense.

 

Sorry for the misunderstanding.

 

Message 16 of 27
(3,469 Views)

knicewar wrote:

Ah.  I understand the source of the flames.  I thought you were implying all global variables were bad, when it now sounds like you were saying that LabView's implementation of global variables is dangerous (no mutexes) -- never mind it's impossible to do what I wanted.  That makes this whole forum thread make more sense.

 

Sorry for the misunderstanding.

 


I would say that the issues associated with globals is not unique to LabVIEW but apply to other languages as well. The one place where you don't run into many issues is when your application is single threaded. When single threaded you don't really encounter race conditions since by definition only one thing can ever access the global at a time. Any system that is multithreaded will encounter issues when using globals.



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 17 of 27
(3,451 Views)

knicewar wrote:

Ah.  I understand the source of the flames.  I thought you were implying all global variables were bad, when it now sounds like you were saying that LabView's implementation of global variables is dangerous (no mutexes) -- never mind it's impossible to do what I wanted.  That makes this whole forum thread make more sense.

 

Sorry for the misunderstanding.

 


Exactly!

 

I am glad you got the message.

 

Re: Sorry....

 

No problem, from my side. I have to be used to it by now and besides I always keep a copy of the "Impossible Dream" around just to keep myself honest.Smiley Tongue

 

Ben

 


To dream the impossible dream,
to fight the unbeatable foe,
to bear with unbearable sorrow,
to run where the brave dare not go...

 

To right the unrightable wrong,
to love pure and chaste from afar,
to try when your arms are too weary
to reach the unreachable star!

 

This is my quest --
to follow that star
no matter how hopeless,
no matter how far --


To fight for the right
without question or pause,
to be willing to march into hell
for a heavenly cause!

 

And I know if I'll only be true to this glorious quest
that my heart will be peaceful and calm when I'm laid to my rest.

 

And the world will be better for this
that one man, scorned and covered with scars,
still strove with his last ounce of courage
To reach the unreachable stars!

 

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 18 of 27
(3,427 Views)

I would like just add 5 cents into this flame, becuase the question was "how to create Globals programmatically".

Action Engines (or Functional Globals) (see link provided by Ben in second post) are very good for such tasks.

In some cases (if data typenot fixed) you can do this based on array of variants, so your Globals will be "programmatically created" for any type, something like that:

 

Screenshot.png

 

the code behind of Functional Global is pretty easy:

 

FG.png

 

Full project in attachment.

 

best regards,

 

Andrey.

 

Message 19 of 27
(3,417 Views)

boostinallovryou wrote:
I have to agree, Ben was the unprofessional one.  "I refuse to help anyone use global variables..." 


You obviously don't know what you are talking about.

 

Ben w-a-s trying to help.

 

And so did many others.  So I won't propose what has already been properly proposed before.

 

 

EDIT portion: I didn't see the 2nd page to this thread 😉

Message Edited by Ray.R on 10-14-2009 11:08 AM
Message 20 of 27
(3,348 Views)