Solved

How to determine if a section exists in a ini file

Posted on 2014-12-05
13
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
13 Comments
 
LVL 47

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 47

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 47

Expert Comment

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

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 47

Accepted Solution

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

Author Closing Comment

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

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 47

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 47

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

738 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