08-17-2010 10:47 AM
Hi,
In recent days I spent much time trouble shooting my program. Basically there is a subvi in the main program. And I put a control on the front panel of subvi. This control is not as a connector terminal -- it just holds some value useful for subvi. I set a default value for it, while in the subvi its value will be changed via local variable of iteself.
Then something unexpected happens. I suppose every time the control will be initialized to defalt value when the subvi is called. But actually it is not! Every time i call the subvi and then the control just holds the value at the end of last time execution! it really subverts my concept about "default value". Could somebody comment on it?
08-17-2010 10:54 AM - edited 08-17-2010 10:58 AM
The current value will remain as long as the VI stays in memory. The default value applies only for the first time the VI is called.
It seems you have some misguided ideas. Why are you changing the value via a local variable if you don't want it changed?
(Please show us the code of your subVI. Maybe there are much better ways of doing things...and we can help. :))
08-17-2010 10:59 AM
If all else fails, you can also force it to return to its default value.
Within the subVI's code, you can reset the control back to its default value before the rest of the code runs.
08-17-2010 11:09 AM
Altenbach,
Thanks for your reply! I think this "misguided idea"is universal.
"The current value will remain as long as the VI stays in memory. The default value applies only for the first time the VI is called."
I think you are right to this case. But if the control is a "connector terminal", the default value must apply for EVERY TIME the VI is called. It is exactly this perception that mis-guides me to believe that default value works for EVERY TIME the VI is called.
"Why are you changing the value via a local variable if you don't want it changed?"
I want it to be changed inside subvi, but not kept value between calls. It is excatly a "local variable" in C language. But LabView treats it as a "static local variable".
Steady
08-17-2010 12:05 PM
08-17-2010 12:08 PM
A 'local variable' and 'global variable' are not exactly what you think they are, if you have your C programmer hat on
They don't exclusively apply to scope; in this case, it doesn't mean that the variable only exists within the subVI.
As with any language, this variable exists in memory from when it is called, until when it is 'destroyed'.
If the variable is being created in the subVI, and the subVI is staying in memory in the top level VI, the variable still exists, and holds its most recent value.
In this case, it is not a 'local variable' as it would be in C because that would mean it would have been destroyed or reset after the execution of the subVI.
I hope that rambling explanation didn't hurt more than help
08-17-2010 12:40 PM
@steady wrote:
Altenbach,
Thanks for your reply! I think this "misguided idea"is universal.
...
Steady
Like the others, I am concerned taht you are using LV as if it is C.
It is not.
Variables are the wires Shift Registers Data Value References etc.
Control and indicators are objects that let the user interact with the code running in the block diagram.
I suggest you post images of your code, let the frequent flyers here beat you up a bit to get you on the right page.
Ben
08-17-2010 04:07 PM
@steady wrote:
Altenbach,
Thanks for your reply! I think this "misguided idea"is universal.
"The current value will remain as long as the VI stays in memory. The default value applies only for the first time the VI is called."
I think you are right to this case. But if the control is a "connector terminal", the default value must apply for EVERY TIME the VI is called. It is exactly this perception that mis-guides me to believe that default value works for EVERY TIME the VI is called.
"Why are you changing the value via a local variable if you don't want it changed?"
I want it to be changed inside subvi, but not kept value between calls. It is excatly a "local variable" in C language. But LabView treats it as a "static local variable".
Steady
Coming from a text based language myself one of LV's biggest mistakes is calling Local Variables for Local Variables as they're Data Copies. What you're after is a Local Wire. 😉
If you need to feedback data through a loop you're after the mentioned Shift Register.
/Y