You are here:About>Computing & Technology>Visual Basic> Using VB.NET> Application Settings in VB.NET 2008
About.comVisual Basic
Newsletters & RSSEmail to a friendSubmit to Digg

Application Settings in VB.NET 2008

From Dan Mabbutt,
Your Guide to Visual Basic.
FREE Newsletter. Sign Up Now!
Jan 27 2008

Clear up the confusion about it!

VB.NET 1.0 introduced a sophisticated new way to save settings for an application. Then VB.NET 2.0 introduced another one. All the while, articles in magazines and on web pages were saying things that were misleading and sometimes outright false. VB.NET guru Duncan Mackenzie wrote in MSDN magazine that, "It's not all that easy to find the correct answer. You'll find a wide variety of solutions on newsgroups and forums, but only a few of the posted solutions illustrate the proper way to handle this requirement."

Even official Microsoft pages get it wrong. Here's an example from Microsoft's official MSDN documentation page, Visual Studio Application Settings. (Hopefully, they will get this page updated soon. But this is the way it was when this article was written.)

"changes in user settings are not written to disk unless the application specifically calls a method to do so"

"user settings are automatically saved before application shutdown"

On the very same web page!

In a different MSDN article, the mystery is cleared up, "The settings are automatically saved only in certain project types, such as Visual Basic Windows Forms applications. In other cases, such as in Class Library projects, you will need to explicitly call the Save method of the My.Settings class."

It's a little disturbing to see problems like this at MSDN. It's like finding out that there really isn't a Santa Claus after all. What's a programmer to do?

The goal of this article is to clear up some of that confusion. Although I've double checked everything here with my own testing, I might have made an error too. If you find one, let me know. Another point worth knowing is that this is an area where Visual Basic's My namespace, unavailable in C#, really helps out since My.Settings is an easier way to handle settings.

On the next page, we'll create and use an application setting bound to a Form component using the Properties window just to introduce the topic. This will be done step by step with a lot of illustrations so there will be no confusion about what's happening. And we'll use free Visual Basic 2008 Express Edition to make sure that as many programmers as possible can follow along.

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.