Simplify your business
Monday, 13 October 2008 11:01 pm

VB.NET inifile class

Thursday, 3 May 2007  

If you’re a VB.NET developer who’s also programmed in the various Visual Basic flavours which preceded it, you would have noticed that the new standard for custom program settings storage is XML files.

We recently did some work on porting an “older” application to the VB.NET platform. Early on in the design process, we discovered that the existing users wanted to retain their original custom application settings.

Settings which were kept in INI files, not XML.

Because the .NET framework does not intrinsically support INI files, we decided to write our own lightweight inifile class. Since our only requirements were (1) to read and write string, integer and boolean settings and (2) backward compatibility, our library only offers “load” and “save” functionality.

To handle string values:

LoadString(Section As String, Key As String, Optional DefaultValue As String = "") As String
SaveString(Section As String, Key As String, Value As String)

To handle integer values:

LoadInteger(Section As String, Key As String, Optional DefaultValue As Integer = 0) As Integer
SaveInteger(Section As String, Key As String, Value As Integer)

To handle boolean values:

LoadBoolean(Section As String, Key As String, Optional DefaultValue As Boolean = False) As Boolean
SaveBoolean(Section As String, Key As String, Value As Boolean)

If they’re the only features you’ll need, download the inifile class and implement it in your current or future project.

Posted in Tips, Visual Basic by Ivan
Blinklist icon Del.iocio.us icon Furl icon Reddit icon Technorati icon Yahoo! icon

Got something to say?

To protect your privacy, your email address will not be displayed.





Some basic rules for commenting:

  • Watch your language.
  • Keep comments on-topic and relevant.
  • You can use basic XHTML tags for formatting and linking but not bbcode.
  • Comments are moderated, so don't double post if your comment doesn't appear immediately.
  • Please proof-read your comments for spelling and grammar mistakes.
  • Watch your language.