NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Member
ashifulk
Posts: 64
0 Kudos
Accepted Solution

Reinitialize some values at start, not all

I'm making a program to take some measurements and I'm using a lot of controls/indicators. I want to reinitialize most of the values to default at the start of the program and at the end. I have 3 values that a user enters before the program starts and I need to retain those values for later on in the program, I can't reinitialize them. Is there a simple way to do this? I can't use the "Reinitialize All To Default". Currently I have all the values, except for the 3 user inputs, set to default at the start of the program by using local variables at the start of the program. But this looks messy and I don't want to do the same thing at the end of the code.

Active Participant
vt92
Posts: 503

Re: Reinitialize some values at start, not all

There is nothing wrong with using locals to reinitialize values as long as you are careful about race conditions. 

 

Otherwise, you could use property nodes, but that is generally frowned upon.  You could bundle the references of all of the controls that you want to initialize, then convert the cluster to an array, then use a FOR loop to re-initialize them.  I would recommend toggling "Defer panel updates" to reduce the performanc hit.  The advantage of this method is that you can encapsulate all of this in a subvi.

 

 



"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
Active Participant
.aCe.
Posts: 674

Re: Reinitialize some values at start, not all

Or you could use something like this:

reinitialise.png



Beginner? Try LabVIEW Basics
Sharing bits of code? Try Snippets or LAVA Code Capture Tool
Have you tried Quick Drop?, Visit QD Community.
Member
ashifulk
Posts: 64
0 Kudos

Re: Reinitialize some values at start, not all

I'm still new to LabVIEW so I'm having a little trobule understanding the "DigNum (strict)" property node... Is that restricting the numbers in the VI from being set to their default value? When I run your code it doesn't work, I keeping getting an error that says "LabVIEW:  VI Reference is invalid."

Active Participant
.aCe.
Posts: 674
0 Kudos

Re: Reinitialize some values at start, not all

Thats because the snippet tools strip the reference. Try the attached vi.



Beginner? Try LabVIEW Basics
Sharing bits of code? Try Snippets or LAVA Code Capture Tool
Have you tried Quick Drop?, Visit QD Community.
Member
ashifulk
Posts: 64
0 Kudos

Re: Reinitialize some values at start, not all

Thank you. I like this idea. I created a simple program based on the shift register concept and attached is the VI. This works from me just testing it out but do you see any problems with using this?

Active Participant
.aCe.
Posts: 674
0 Kudos

Re: Reinitialize some values at start, not all

Sorry, I am using Labview 2011 so cannot open youe code!



Beginner? Try LabVIEW Basics
Sharing bits of code? Try Snippets or LAVA Code Capture Tool
Have you tried Quick Drop?, Visit QD Community.
Member
ashifulk
Posts: 64
0 Kudos

Re: Reinitialize some values at start, not all

[ Edited ]

Attached is a screenshot of the code... It's pretty simple, so I don't think the VI is needed.

Knight of NI
Knight of NI
tst
Posts: 10,924

Re: Reinitialize some values at start, not all

There is a separate reinit method for each control, so I would suggest something like the following (2011), which resets all controls except the ones in the array.

 

Of course, if you only want to reset a few controls, you build their references into an array and call the reinit method on them.


___________________
Try to take over the world!
Trusted Enthusiast
P@Anand
Posts: 2,495
0 Kudos

Re: Reinitialize some values at start, not all

[ Edited ]

tst wrote:

There is a separate reinit method for each control, so I would suggest something like the following (2011), which resets all controls except the ones in the array.

 

Of course, if you only want to reset a few controls, you build their references into an array and call the reinit method on them.


You gave me new learning today. So Kudos!

-----

The best solution is the one you find it by yourself