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: 

Equivalent of "C static local" variable?

Hi!

I am trying to write a sub-VI that has multiple call modes
(init, do1, do2) and needs to remember some variables set in the
'init' call. When I try the straightforward way of just placing
indicators as temporary variables on the front panel, these seem
to reset to the default values every time the VI is called.

Is there any equivalent of the static local variables used in C?
Or do I have to use GLOBAL variables?

Rudolf
0 Kudos
Message 1 of 9
(4,368 Views)
There are several solutions:
1. Global variables.
You can create global variable for each of your temorary variables. This is easy to do but I think it's not very convivient way to pass data.
2. One Global variable.
If you have many temporary variables you can organize them into cluster and create only one global variable for this cluster. Then you have to read and write this cluster in your SubVI every time you change any of your temporary variables.
3. Pass data to/from your SubVI.
If you look at the most of LV VIs you will see that very often they have some practically identical input and output nodes. For example "AI Start.vi" has " task ID in' and "task ID out" nodes. You can make the same thing. Let your subVI reads and writes some cluster of your tempora
ry variables through its input and output nodes. So you will have the access to this variables in any place ofyour main VI. Also you can change and create your own clusters of temp variables in your main VI. And also you will get the ability to pass these data to your subVI using local variables or shift registers or sequence locals in your main VI

I think that the last way is the most useful.

Good luck.

Oleg Chutko.
0 Kudos
Message 2 of 9
(4,368 Views)
Simpler and closer to the current method; reinit to default only occurs on
calling a VI for those controls which are wired to the connector pane and
which do not have data coming in from the caller. If a control does not have
a connection on the connector pane, it is static local without having to go
outside the encapsulated "object" that is the VI.

Alternatively, having a while loop inside the VI with un-initialised shift
registers has the same effect- the data persists between executions.

--
Craig Graham
Physicist/Labview Programmer
Lancaster University, UK


"Oleg" wrote in message
news:506500000005000000E35B0000-1011517314000@exchange.ni.com...
> There are several solutions:
....
> I think that the last way is the most useful.
0 Kudos
Message 3 of 9
(4,368 Views)
Hi Rudolf,

Craig's comment has the answer you are looking for.
An un-initialized shift-register in LabVIEW is the same as a static local in "C".

If you need more inforamtion please comment on this answer and will get back to you the next buisness day.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 9
(4,368 Views)
Rudolf,

Perhaps this should be taken to the "Designs" Topic. This is a matter of a simple design of a multi-use function. This is a very common design that we use here. If you go to that topic, and look under submitted designs, you will see a very good example of this implemented in a more complex design (the design I submitted actually contains two designs. The more complex design rests on top of the multiple function design.)

Check it out and see what you think. I don't know what the scope of a static local is in C environment, but in LabVIEW, an unitialized shift register, which is a common element in this design, has global scope to the application environment. This method is also how we implement global variables. The submitted design also con
tains this sub-design element, that is, a "LabVIEW 2 Style Global" or "Un-Initialized Shift Register Global" or whatever name you prefer.

I hope this helps. It is a bit redundant, but I felt it important to mention that this is in fact a design solution. Perhaps I can garner some interest in that topic.
0 Kudos
Message 5 of 9
(4,368 Views)
How can i use "static locals" in the sense of unconnected control panels and avoid using
property knots (value)?
Using one of these always leads to mass using of it because of chain of destiny.
Is it common to return a variable from a sub vi to the main program, which it can read
and pass to the sub vi in the next run again just like a shift register in while loops?
 
Sneff
 
 
0 Kudos
Message 6 of 9
(3,926 Views)

Well, instread of adding to a six year old thread (from 2002!), you should have probably started with a new thread.

Sorry, I don't understand your question. What is a "chain of destiny"? Did you use an online translator for your question?

0 Kudos
Message 7 of 9
(3,924 Views)
0 Kudos
Message 8 of 9
(3,918 Views)

See Action Engines to see how static locals can be used in LV.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 9 of 9
(3,907 Views)