[RESOLVED] Counting the number of items under a section in an ini file.
Hi all
Looking for a little help, I have a display system that I created in VS Studio 2005 that uses ini files for certain functions. Reading and writing to ini files is easy enough but what I just can't figure out is how to count the number of items under a particular ini section. Any help is appreciated
Cheers Dougie
Re: Counting the number of items under a section in an ini file.
Hi
I am a little further on
Code:
Private Sub ReadIni2()
Using r As System.IO.StreamReader = New System.IO.StreamReader("c:\Myinifile.ini")
Label2.Text = 0
Do While r.EndOfStream = False
If r.ReadLine = "[MySection2]" Then
Do While r.EndOfStream = False
If r.ReadLine.StartsWith("Item") Then
Label2.Text = Label2.Text + 1
Else
End If
Loop
End If
Loop
End Using
End Sub
Basically the above reads through the whole ini file, when it gets to the [Mysection2] it then counts all the items beginning with "Item". So it sort of works, unfortuantly it also counts any other items beginning with "Item" from that point on, what I need is it to stop counting at the end of the specified section.
Cheers
Dougie
Re: Counting the number of items under a section in an ini file.
Hi. Would it be possible to post your INI file here, so that we can also play with it. Perhaps someone can then come up with a solution.
Re: Counting the number of items under a section in an ini file.
Hi
The ini file is very basic.
[Setup]
Database="Database Location"
[MySection1]
Item1 = ""
Item2 = ""
Item3 = ""
[MySection2]
Item1 = ""
Item2 = ""
Item3 = ""
Item4 = ""
[MySection3]
Item1 = ""
Item2 = ""
Item3 = ""
Item4 = ""
Item5 = ""
Item6 = ""
Re: Counting the number of items under a section in an ini file.
Look at this logic:
Code:
Label2.Text = 0
Do While r.EndOfStream = False
If r.ReadLine = "[MySection2]" Then ' Only for a section
Do While r.EndOfStream = False ' if you have more
If r.ReadLine.StartsWith("Item") Then ' and it starts with...
Label2.Text = Label2.Text + 1
Else
r.ReadAll() ' Skip to end of file
End If
Loop
End If
Loop