Save options for your program (when it starts)

NicoVB

Well-known member
Joined
Jan 2, 2002
Messages
160
Location
Belgium
What is the best way to save options for your program like sound, file location, and so on???

in XML files, text files???
 
With the project Im running, I just use the builtin SaveSetting() and GetSetting() functions.

Format (All args are type String):
GetSetting(HKCU Folder, SubFolder, Key, Default Value If Key Not Found)

SaveSetting(HKCU Folder, SubFolder, Key, Value)

(Caveat - This places the folder under "HKCU\Software\VB and VBA Program Settings" - Cool for some of us, but if youre deploying something name-worthy, Im not sure how to keep it from sticking it there)

Example:
Dim SaveDir As String = GetSetting("MyProj", "Settings", "FileLocation", CStr(MyDocs) & "\MyProj Personal Files\")
Or
SaveSetting("MyProj", "Settings", "FileLocation", InputBox1.Text)

---
Just as an added bonus, Ive seen a lot of people asking for a way to find out the current "My Documents" directory, since it is changeable and will vary on a multi-user machine.. the way I do it is just with a couple little lines at the top:
Dim aKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders")
Dim MyDocs As Object = aKey.GetValue("Personal")

Also note you must use an "Imports Microsoft.Win32" to use the RegistryKey type

Hope this helps!
-Morgon
 
Hmmm, but is there not something with a config XML file???

I heard something about this, but dont know very sure.


BTW : The GetSetting and SaveSetting Functions: were are your options saved????
 
I like using XML, check out the XMLTextReader and XMLTextWriter classes.
 
Im curious.. why is XML better than using the registry, or even just an INI file? Is it "coolness factor" or is there some real benefit?
 
Okay, well Captain 37337.. why does XML rox .. is it just like an INI file, or what? Ive only seen XML as its own file.. so is it just "INI 2.0" or what? Someone enlighten me :)
 
Everything taken together, XML is to INI as the ocean is to small
pond. That doesnt mean it would be better when all you need is
a simple way to save some options, but as has been said, XML is
on the MS marketing machine top 10 list.
 
Originally posted by NicoVB
The GetSetting and SaveSetting Functions: were are your options saved????
HKEY_CURRENT_USER - software - VB and VBA Program Settings - application name (you can specify this one) - subkey (you can specify this one to - value (pretty logic that you can specify these too)
 
Back
Top