LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I programmatically create and use a global variable?

I have an app where the number of AI DAQmx tasks I create are specified in a config file.  I have a monitor task that periodically looks at the latest values from all DAQ tasks.  I've been doing this with a set of global variables because it was the simplest way to do it.  But to do this, I have to explicitly create a separate AI task that uses the hard-coded global variable name for the DAQmx samples.  I would prefer to only write one VI for the DAQ loop that writes to a global variable that I programmatically create based on the config file.  The only solution I can think of is to use a global variable "pool" that is sized bigger than I expect to need, and then have a big switch case to select which one I want based on the task index.  But this sounds pretty silly.

 

0 Kudos
Message 1 of 27
(8,019 Views)

Sorry but I refuse to help anyone to use Global varibles. Doing so would be like teaching someone how to play Rusian Roulette!

 

Instead create an Action Engine that stores an arrays of teh refs you want. Add actions and controls to index out the one you want. Since it willbe an array you can add or delete as required.

 

Ben

 

 

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

Hi knicewar,

 

what about an array of values? Size can change at runtime, only one global name, each task has it's own index.

What about a FunctionalGlobalVariable, that also handles assigning indices to new tasks?

Best regards,
GerdW


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

Wow, what a jerk!  I don't see how an "action engine" is any different from a global variable other than being more VI code to manage.  In spite of what your old software teacher told you, global variables are not all evil and they still have valid uses.  People try to call them different things like singletons or whatever to make themselves feel better, but when you need to represent a global resource to all your threads, there needs to be a variable that has global scope.

 

 

0 Kudos
Message 4 of 27
(8,002 Views)

knicewar wrote:

Wow, what a jerk! 


Gee, that's such a professional response. I'll have to remember your login name for next time.

 

Both suggestions provided have their merit. Perhaps you should spend a little more time to look into the suggestions and see why they were given by others who clearly have more experience than you do, and less time disparaging those of us who are VOLUNTEERS and try to help those WITHOUT BEING PAID BY NI.

Message Edited by smercurio_fc on 10-09-2009 12:26 PM
Message 5 of 27
(7,977 Views)

Ben wrote:

Sorry but I refuse to help anyone to use Global varibles. Doing so would be like teaching someone how to play Rusian Roulette!

 

Instead create an Action Engine that stores an arrays of teh refs you want. Add actions and controls to index out the one you want. Since it willbe an array you can add or delete as required.

 

 


Hey, hey ,hey... In some cases Globals ("as is") also may be fully acceptable! Why to develop you own super-puper bike, while you have already "ready-for-use" bicycle?!

But especially in described case - Functional Globals exactly what he needed.

 

Andrey.

0 Kudos
Message 6 of 27
(7,971 Views)

"Gee, that's such a professional response" -- hey, I was asking for help and I get "I refuse to help someone who uses global variables".  Who's being unprofessional?

 

Message 7 of 27
(7,956 Views)
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
0 Kudos
Message 8 of 27
(7,953 Views)
I tend to agree with Ben. I don't buy the concept of taking the asy way out (globals) because it very rarely will things remain static. You almost always have to extend the features and functionality of an application and then you will run into issues with sloppy and lazy implementations. The solutions offered may require a little time to learn but once you do it doesn't really require any extra effort.


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 9 of 27
(7,942 Views)

Hi knicewar,

 

you ask for something impossible ("programmatically create and use globals"), but don't accept ideas to solve your problem?

 

I suggested using an (global) array to hold all values and suggested to go one step further in using an AE/FGV to handle the index assigning (you would have to do this anyway). So why not get back to real discussion?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 10 of 27
(7,927 Views)