I am not an IT professional, so I apologize if I missed something obvious.
When writing a program, I add the SettingsIni class, which reads a text file of keys and values. I think this method is really flexible, because the parameters can be added or changed without changing any code, regardless of which application I bound it to. Here is the main code.
Public Shared Sub Load() Using settingsReader As StreamReader = New StreamReader(System.AppDomain.CurrentDomain.BaseDirectory & "settings.ini") Do While settingsReader.Peek > -1 Dim line As String = settingsReader.ReadLine Dim keysAndValues() As String = line.Split("="c) settingsTable.Add(keysAndValues(0).Trim, keysAndValues(1).Trim) Loop End Using End Sub Public Shared Function GetValue(ByVal key As String) Dim value As String = settingsTable(key) Return value End Function
This allows you to use the parameter in your code by calling the SettingsIni.GetValue method.
For instance:
watcher = New FileSystemWatcher(SettingsIni.GetValue("inputDir"), "*" & SettingsIni.GetValue("extn")).
I find this makes my code readable. My problem is the values ββin this case, inputDir and extn , are manually typed and are not checked by intellisense. I am always worried that I can make a typo in the rarely used application branch and skip it during testing. Is there a best practice method for retrieving settings? or a way around these unverified values ββof imprinted characters?
source share