LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset a variable to default value after a case execution

Dear all

 

For my application, I need to reset the value of a variable after executing a case in a case structure. I am attaching a simple .vi file of my problem.

Here, Var A is the variable that is being updated after execution of each loop. If I need to reset it to its default value, how can I do that?

Please let me know at your earliest.

 

Thanks

Kanak

0 Kudos
Message 1 of 5
(5,206 Views)

A control can be reset by creating an invoke node for the control.  Right click the terminal -> Create -> Invoke Node -> Reinitialize to Default.  Use the error line to enforce a predetermined execution order.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 5
(5,177 Views)

You might give some thought about what you are trying to do with your variable.  I see Shift Registers not really being (properly) used in your code, what look like Global Variables used a "temporary storage", and other very "un-LabVIEW-like" processes.

 

LabVIEW is a data-flow language.  The data live in the wires (sort of). and if you want to keep them around inside a loop, a Shift Register is the usual way.  If you understood this, you could probably have figured out how to reset a value being stored in a Shift Register (and thus "evolving" inside the loop) to its value when it entered the loop (which may be what you are trying to do), something like this, which counts up slowly from Pi, resetting when Reset is pressed ...

Set Default.png

Note that the Reset button is a renamed "Cancel" button from the Boolean Palette.  If you understand why I did that, give yourself 2.5 point on the CLAD exam.

 

Bob Schor

 

0 Kudos
Message 3 of 5
(5,172 Views)

Dear Bob

 

Thanks a lot for your reply. I understood what you did there. I cannot reset my variable by a cancel/reset button, nor I can use a while loop to do that. I would prefer a case structure.

 

Maybe, I was not clear with my problem in the first place. For my application, I need the variable to be reset to its default value after execution of the case, I cannot use a reset button for this. I have been able to do the reset using invoke node. Now I am kind of stuck with how to show the two states using one indicator(state 1- inside the case; state 2- after case ends). I have been looking for an example to do that. 

 

Thanks for your help.

 

Thanks

Kanak

 

0 Kudos
Message 4 of 5
(5,165 Views)

I used a Selector instead of a Case, and "powered" it with a Reset Button.  But the principle is the same -- you hold the "changable variable" in a Shift Register, where it retains its (possibly-changing) value.  You also bring its Initial (default) Value into the loop so that whenever it is appropriate (a particular Case of a Case Statement, for example, you replace value in the Shift Register with the Initial Value, as I did in my example.

 

Bob Schor

0 Kudos
Message 5 of 5
(5,149 Views)