Sorry, I missed the fact that that code didn't look up a specific section. So forget that and try this instead:
Code:
Dim inifile As String = System.AppDomain.CurrentDomain.BaseDirectory() & Replace(LCase(IO.Path.GetFileName(Application.ExecutablePath)), ".exe", ".ini")
Dim objReader As New System.IO.StreamReader(inifile, System.Text.Encoding.Default)
Dim row As String
Dim section As String = "Links"
Dim match As Boolean = False
Do While objReader.Peek() <> -1
row = objReader.ReadLine()
If LCase(row) = "[" & LCase(section) & "]" Then
match = True
ElseIf match AndAlso Trim(row) <> "" AndAlso Mid(row, 1, 1) <> "[" Then
Dim data() As String = Split(row, "=")
Dim key = data(0)
Dim value = data(1)
Debug.Print(key & "=" & value)
'listbox.Items.Add(key & "=" & value)
Else
match = False
End If
Loop
objReader.Close()
Change the value for
inifile to the path and filename to it. The value for it above is something I use to avoid having hard coded paths and file names. It takes the current directory and the name of the exe and changes exe to ini. When you run the program from VB it means the bin folder in your project folder. So it looks for an ini file with the same name as the exe file, in the "current directory".
Then set the value for
section. I've added a commented example of how to add the key and value to a listbox.
The code will read line by line looking for the section. After it finds it it will read the following key/value lines until it reaches either an empty line or a new section - row value beginning with [