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.
|