LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Initializing path of configuration file only once

Solved!
Go to solution

Hi all,

 

I have a program where a user can change settings and since default values on the front panel cannot be changed at run time, it is saved to a configuration file (I'm using MGI Read/Write Anything). The config file is then programmatically opened and used to run a separate test program. The user can technically always enter into the settings again to view or edit and the front panel will load the file from the last saved path and display the last saved options. Anytime it is saved, it will overwrite the old file. 

 

Right now, it all works because the initial path that is called is a constant. However, when the software is given to a customer, they might want to save it somwehere else in a folder of their choosing. 

 

While I can change the constant to a control with a dialog box, the dialog box would pop up everytime the user enters into the settings (and they might not remember where they saved it in and would result in multiple config files created in different locations), but what I want is to be able to have that dialog box only once (when it is first installed), and everytime when that vi is called, it will automatically load the config file from that path. Note that the user can later choose to save to a new path and only that path will be called subsequently. 

 

TL,DR

1) User first installs the program and they should set the configuration files in a path that they want

2) When a hypothetical 'view settings' is triggered, it automatically calls from that path and the file can be edited and overwritten

3) After some time, the user decides to save in a new path

4) When the setting is triggered again, it automatically calls from new path 

 

I feel the example I attached *might* work (but probably not since default values on the front panel cannot be changed at run-time and I neither want to set a blank as default nor an actual path since it does not currently exist outside of my development computer) but I feel iffy about the local variables and there must be a better way to do this.

 

Thanks in advance.

0 Kudos
Message 1 of 4
(1,419 Views)
Solution
Accepted by topic author nikvl

Use two configuration files.

 

1.  What you have now that contains the program settings and gets saved wherever and whenever the user wants.

2.  One you keep in the application's program data directory.  It is always there.  It sole purpose is to contain the last saved file path of the big configuration file.

 

When the program starts, it reads #2 so it knows where to find the original configuration file (#1).  When they save a new config file or change its location, your application updates the file in #2 to store the new file path.

0 Kudos
Message 2 of 4
(1,408 Views)

Thanks for replying.

 

I'm sorry, but I don't quite know what you mean exactly for 2.

 

I tried visualizing through the attached snippet but wouldn't the same problem crop up where a file dialog would always pop up since the start path control is initialized to default (in this case, an empty path) when the program is restarted?

0 Kudos
Message 3 of 4
(1,356 Views)

You initialize the path to what you read from the configuration file that is always in c:\program data.

 

You only call the file dialog if that path read from that file is empty, or if the user presses a button or does some action where they say they want to save to a different path.

 

Once a new path is chosen, then you update the config file in c:\program data to save the new path for the next time around.

Message 4 of 4
(1,327 Views)