LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

creating a user preferences file

Solved!
Go to solution

Hi, all -

 

I just got a request to save a few program settings, and read those settings on startup. Seems like I need to create a preferences file. (If there's a better way, please advise.)

 

I know nothing about doing this. Any words of wisdom? My first thought would be XML, though it looks like I'l have to install the device drivers to use it.

 

1. good idea/bad idea?

2. where do preference files normally go?

3. are preference files generally invisible or somehow rendered uneditable by the user?

 

Input on this, or anything related, would be appreciated. Thanks!

 

mz

0 Kudos
Message 1 of 9
(3,962 Views)

Yes, XML is one possible choice but it's not the only one (and in my opinion not the best one either).

 

As alternatives I cann suggest:

 

  • Using a simple file to store informations with a format you choose, either in text or binary format depending on whether you want them to be public or not
  • Using .INI files: CVI comes with an instrument to read/write them that works like a charm
  • Storing informations in the registry (in the Programmer's Toolbox there are functions to read/write keys in the registry)

I personally use an .INI file in each application I write to store configuration and user options and I alway find me confortable with it.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 9
(3,956 Views)

No words of wisdom Smiley Wink, but I am also using ini files. Compared to registry settings I like the fact that in case of problems (say, the program crashed due to a power failure) the file can be edited easily.

 

For more information, see here and the example ini.cws

Message 3 of 9
(3,953 Views)

XML is most modern way of storing application data(eg-preferences) in files in text format and is heavily standardized.  But you have to go through a moderate learning curve before you can read and write to and .XML file. But this is worth if you want to store tons of data in neatly organized manner. CVI supports this file standard in form of CVIXML instrument driver typically found in the following path...

C:\Program Files (x86)\National Instruments\CVI2012\toolslib\toolbox\cvixml.fp

Once you loaded this instrument driver, you can start using the functions in them to start reading and writing to XML files (assuming you have basic understanding of XML format).

 

Storing data in .ini files is also a standard way of storing application initialization/configuration data, but is old fashioned. But is simpler. I donot have much experience with .ini files.

 

The quickest and easiest way is to write and read from a file is using standard ANSI C functions

fopen(), fprintf(), fscanf() ,fclose(). fprintf and fscanf are very similar to printf() and scanf() functions except that they take filepointer returned by fopen() as additional arguments. These functions should serve your purpose for now as only little data needs to be stored. Note that the preferences file you create is not in standardized format, unlike .ini or .xml.

 

Preferences file can be stored in same folder as .exe file, so that you do not have to provide full path to access this file. And if you copy your folder containing .exe to somewhere else, you dont have to change your code. I think this is also valid when you have multiple accounts on same computer and application can be launched by any of the users.  This is also a good place, if you donot want users to edit preferences file, except in special situtations.

 

It is possible to make a file hidden or made read-only, but I donot know whether this can be done through CVI. But this is not of much use as users can always unhide it / make it writable. If you really want to prevent its data from being manipulated, either store the data in binary format (fread(), fwrite()) or better encrypt your data.

 

Regards,

Sudhir

 

Message 4 of 9
(3,942 Views)

Thank you for the detailed replies, everyone. I think I'll take a crack at using .ini files. I can't find anything in the help about them, probably because I don't know the name of what to look for. Can someone point me in the right direction, please? 

 

 

0 Kudos
Message 5 of 9
(3,929 Views)
Solution
Accepted by topic author mzimmers

Wolfgang wrote:

For more information, see here and the example ini.cws


Did you follow the link? Searching for Ini in the CVI Help will display this information... Or what else are you looking for?

0 Kudos
Message 6 of 9
(3,925 Views)

Oops. Sorry, Wolfgang. My middle-aged eyes don't always pick up everything they should. Thanks for that link; that should be enough to get me going.

0 Kudos
Message 7 of 9
(3,922 Views)

I agree with the others; INI is the way to go.  It's easy in LabWindows, it's very readable for your users.  It's ASCII.  And due to its structure, parsing an INI is really built into the format.  In other words, you can very easily lookup values from the file without any elaborate Scan() functions and line parsing.

Message 8 of 9
(3,895 Views)

Thanks again for the input, everyone. I've implemented a preferences file that seems to work very nicely, using the .INI approach you all recommended.

0 Kudos
Message 9 of 9
(3,888 Views)