Solved

How to determine if a section exists in a ini file

Posted on 2014-12-05
13
168 Views
Last Modified: 2014-12-05
I have class i use for making and getting ini values and need to determine if a section exists

Sub OpenWonLost()
    Dim fName As String
    fName = gMyPath & "\KenoData.ini"
    Set clsINIFile = New cInifile
    
    With clsINIFile
    .Path = fName
    .Section = txtDescription.Text
    .Key = "TotWonLost"
    .Default = 0
    mcurWonLost = .Value
    
    .Key = "TotalRuns"
    .Default = 0
    mlTotalRuns = .Value    
    End With
    mbNewSession = False
End Sub

Private Sub txtDescription_Change()
SectionExists txtDescription.Text
  If SectionExists = False Then
    mlTotalRuns = 0
    mcurWonLost = 0
  Else
    OpenWonLost'get the saved values
  End If
End Sub

Open in new window


Function SectionExists(txt As String) As Boolean
'if section exists then true
'need help here
End Function
class attached
CINIFILE.zip
0
Comment
Question by:isnoend2001
  • 8
  • 5
13 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483324
There may be a better way, but you could just open it as a regular text file and look for the section name line by line.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483333
0
 

Author Comment

by:isnoend2001
ID: 40483369
Thanks Marty
i don't understand this line:
S = ReadIniSection("c:\windows\win.ini", "MAIL")
What does MAIL mean ?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483372
"Mail" is the name of the section.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483374
I can put together a demo project if you like.
0
 

Author Comment

by:isnoend2001
ID: 40483380
Yes a demo would be great
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40483419
0
 

Author Closing Comment

by:isnoend2001
ID: 40483441
Thanks, got it
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483509
YW
0
 

Author Comment

by:isnoend2001
ID: 40483517
Marty This seems to simplify as your first comment(text file)
Function SectionExists(txt As String) As Boolean
Dim fName As String
    fName = gMyPath & "\Keno.ini"
    Dim IniText As String
    Dim strInFile As String
    Dim f As Integer
    Dim l As Long
   
   
    f = FreeFile
    Open fName For Input As f
        Do Until EOF(f)
            Line Input #f, IniText
         If InStr(IniText, txt) Then
          SectionExists = True
            MsgBox "found"
           
            l = l + 1
            End If
        Loop
    Close #f
End Function
do you see anything wrong ?
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483543
I haven't tested it but why do it that way when my demo project is so much simpler?
0
 

Author Comment

by:isnoend2001
ID: 40483574
Because down the road i might get confused with 2 different places referring to ini files
Form level and class
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40483676
I don't understand what you mean but that's OK.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question