-
March 27th, 2012, 06:43 PM
#1
[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
Last edited by 1druid1; March 29th, 2012 at 11:57 AM.
-
March 28th, 2012, 11:11 AM
#2
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
-
March 28th, 2012, 11:17 AM
#3
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.
-
March 28th, 2012, 12:18 PM
#4
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 = ""
-
March 28th, 2012, 04:30 PM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|