Solved

How to determine if a section exists in a ini file

Posted on 2014-12-05
13
133 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 45

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 45

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
 
LVL 45

Expert Comment

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

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 45

Accepted Solution

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

Author Closing Comment

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

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 45

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 45

Expert Comment

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now