Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub ParseIniFile()
- Dim currentSection As String
- Dim Id As Integer = 0
- Dim setting As Setting
- Dim newSettings = New List(Of Setting)()
- Dim sectionQuery = From item In IO.File.ReadAllLines(appIniLocation)
- 'example line (first setting from app.ini)
- 'allowHardwareStreams=1 ; try to use hardware streams if available
- 'find section headers
- i = 0
- For Each item In sectionQuery
- If item.StartsWith("[") Then
- ReDim Preserve sectionHeaders(i)
- Dim itemSplit() As String = Split(item, "[")
- Dim itemSplit2() As String = Split(itemSplit(1), "]")
- sectionHeaders(i) = itemSplit2(0)
- i += 1
- End If
- Next
- 'creating list of settings (the object)
- i = 0
- For Each line In sectionQuery
- setting = Nothing
- setting = New Setting()
- If line = "" Then
- 'this means we're in a new section (it should anyways)
- i += 1
- ElseIf line.StartsWith("[") Then
- 'this will be the section name for the next group of settings
- currentSection = sectionHeaders(i)
- Else
- 'split line to more easily choose what we want
- Dim x1() As String = Split(line, "=") 'setting name -> x1(0)
- Dim x2() As String = Split(x1(1), " ") 'setting value -> x2(0)
- Dim x3() As String = Split(x1(1), ";") 'setting description -> x3(1)
- setting.Id = Id
- setting.Section = currentSection
- setting.Name = x1(0)
- setting.Value = x2(0)
- setting.Description = x3(1)
- Id += 1
- End If
- newSettings.Add(setting)
- Next 'Program stops here (after completing the for loop) for some reason, not entirely sure why
- 'This line and those after it are never reached
- 'replace old list and populate with new
- settings.Clear()
- settings.AddRange(newSettings)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment