LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Default value of a control in a subvi

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?

 

0 Kudos
Message 1 of 8
(4,861 Views)

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. :))

0 Kudos
Message 2 of 8
(4,855 Views)

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.

Cory K
0 Kudos
Message 3 of 8
(4,843 Views)

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

0 Kudos
Message 4 of 8
(4,838 Views)
Don't abuse front panel objects as "variables". That's not their purpose. The are there to communicate with the user. Try an initialized shift register instead.
Message 5 of 8
(4,818 Views)

A 'local variable' and 'global variable' are not exactly what you think they are, if you have your C programmer hat on Smiley Very Happy

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 Smiley Tongue

Cory K
0 Kudos
Message 6 of 8
(4,815 Views)

@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

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

 


@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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 8 of 8
(4,787 Views)