Best way to save settings?

fherrera
07-13-2004, 09:10 AM
Hi there, I just recently found xtremevbtalk and am quite disappointed I hadn't found it earlier! It's an active VB.Net board which for some reason was hard for me to find.

In any case, here's my question.

I am trying to evaluate the many different methods of saving program options. Personally, this is one of my first programs in VB.Net and it is quite small, just basically a GUI for an Excel spreadsheet. In any case, there aren't too many options I'd have to save one of course being a path to where the current spreadsheet lives.

From my experience or lack thereof, here is what I think a decent list:

Write to Registry - I think this might be easy to do in .Net but I'd rather not as I only have a few options to save and well, i'd rather not mess with the registry.

Write to a static file - Either a straight text file or perhaps an XML file (which i'm leaning towards since i've never done it before). Create a format that will suit my needs and write to it and then read from it in order. Simple, right?

Last is some form of serialization - I don't actually know much about this but I read somewhere that you can create a settings class and then serialize it to a file when the program closes and de-serialize the file when the program opens. Umm, I don't actually know anything more than this. But it has been awhile since i've used classes -cough- but the prospects of learning more about serialization add some motivation.

In any case, the static text file seems to be the easiest. I was wondering if everyone agreed or which method you personally use and perhaps why? I'm probably missing some other methods too...?

Last, if the file gets deleted or changed to some invalid format there would have to be some validation when reading it. My guess would be to hardcode some "default" values in the program that it would reset to if no settings file exists, but the "validation" of an improperly changed settings file sounds a bit harder. Just validate each variable as it gets read in and if any of them don't check out start from scratch (back to the default)....

Anyway, your thoughts would be appreciated :D Thanks.

Frank

PWNettle
07-13-2004, 09:55 AM
.Net has some built-in xml configuration support via the app.config file - but the built-in functionality is read-only. Reboot did a nice little writeup on this topic and included a way to write out the settings too in this knowledge base thread (http://www.xtremevbtalk.com/showthread.php?t=131671).

For small apps with simple settings I'm still fond of using the registry and I really like the registry support in .Net.

I'd also mention that MS has a free "application block" available that handles configuration stuff and gives you tons of options - but it's probaby a bit overkill for a simple app (it involves some setup and is made up of a lot of code since it can handle registry, xml, encryption, and more). You can search for "config application block" at MS sites to find it, amongst other "application blocks" they've put together for common functionality.

With options like the registry and reasonably readily available xml config file support I'd be less inclined to use a simple text file for settings - but it could still be an option and I still use them for simplicity while building up simple apps. I mean, if you have a simple app you probably don't want to have more code handling your settings than you do handling your processing!

Paul

fherrera
07-13-2004, 11:12 AM
Wow. That's great. I think i'll try the xml settings file idea as it's slightly more complicated than a text file and a step towards "learning something new" Then I can pretend to know XML :)

Thanks for the reply!

Frank

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum