Community Documents

cancel
Showing results for 
Search instead for 
Did you mean: 

Easy saving and loading of control values

Summary:

Like many people, I often want to save the values of specific controls to file when I exit a dialog and then load them back again, even if I closed the application.

There are any number of ways of doing this (from using local variable and explicitly saving the values to using VIs like the one OpenG has which saves the entire panel), but this is the one I usually use, mainly because it makes it extremely easy to save the values of specific controls.

Function:

To make it easy to save the values of specific controls to a file and load them back into the controls later.

There are two main VIs - the first accepts a reference to a configuration file and does the actual saving and loading and the second is a wrapper which picks a file automatically, making it extremely simple for the user (see the video for an example).

Steps to execute code:

  1. Open the LLB and run the top level example VI.

  2. When you press the OK button, all the values will be saved to a file, so that if you run the VI again, the values will now be loaded from the file.
  3. If you place these VIs in your user.lib folder, you should be able to use them for all your projects. Perhaps I'll make a VIPM package which installs them.

Screenshots:

This video shows an example of how the VI is used, as well as where the automatic file is created and what it looks like. For some reason I can't embed it, so here's the link:

http://www.screencast.com/t/9G90X8jIx

This shows how the wrapper VI is used to very easily save and load:

Load_Save_CTLs.png

This shows the BD of the actual VI which saves and loads the values:

Read_Write_Controls.png

VI Snippet:

None.

VI attached below (LabVIEW 2009)


___________________
Try to take over the world!
Comments
G-Money
NI Employee (retired)
on

Nice implementation! This is a common user functionality that people code up. We have examples of writing the values to TDMS, Text, and Binary files on the community but I couldn't find one using a config file.

peter_smith
Member
Member
on

Hi! I really like how easy and fast is the usage of your implementation. However I think it is not a good idea to save values in an .ini file as binary representated data. These files are great because they are human readable (vs. e.g. an XML file ), and if you want to change some values off of the program, manually, you can simply do it in e.g. notepad.

I also use .ini files many times, but earlier with OpenG's variant config VIs, but sometimes I have to save U64 values, and I really hate those situations when I have to manually correct a file after the deployment for any reason.

tst
Knight of NI Knight of NI
Knight of NI
on

In response to both comments - the fact that this uses the INI VIs is purely an implementation detail which was chosen because they ship with LV and because INI files can be expanded cleanly (i.e. the user can easily add a reference to another control to the array and the old values are not lost). The main consideration here is about the ease of use with which a user can save and load specific control values and the user isn't expected to care about how the values are actually stored.

The same basic API can be used to wrap alternate persistence methods (be it TDMS, binary files, a database, the OpenG VIs Peter mentioned, which I actually do use in my code, or any other), but I don't think that would be needed for the vast majority of people. In this case, simple = better.


___________________
Try to take over the world!
MonicaR
Member
Member
on

Hi!

I usually use OpenG's variant config VIs for this reason - just like as Peter said, but this way seems to be more easy to use, as I don't nedd to make clusters with my config data. Nice code!

Monica

A.Salcedo
Active Participant
Active Participant
on

Hello. First of all thanks a lot for showing us your implementation.

To use it, have I to implement your coide in the same VI of my application or I can be implementated in another vi ?

 

Thanks a lot.

aanderson
Member
Member
on

Your example works very well, and I appreciate the work you have done to make it easy to understand. I am having some trouble getting it to work in my VI however.

I have a VI that prompts a user to input an IP Address in order to connect to a device. When the user clicks connect, I want it to write the IP Address string to a file so it can be loaded if the user closes and re-opens the program later.

I am using your Read and Write Controls to Config File.VI and the only reference I am inputting is the String Reference. At the launch of the VI I am calling a Read, and when the user clicks connect after inputting the IP Address I am calling a Write. When I open the file that is created,there is no data other than the title of the VI. Is there a limitation to the VI that I don't know about or is there something obvious that I am doing wrong?  

aanderson
Member
Member
on

Disregard my question. 

After some more troubleshooting, I saw that it created the file but didn't write the value. I had mistakenly deleted the Label on the String Control for the IP Address so it was not writing anything to the file. After assigning it a label (doesn't have to be visible), it wrote to the file and worked as intended. 
Excellent example, I'm bookmarking this for later. 

Contributors