Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to determine if a section exists in a ini file

Posted on 2014-12-05
13
Medium Priority
?
245 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 49

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 49

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 49

Expert Comment

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

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 49

Accepted Solution

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

Author Closing Comment

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

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 49

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 49

Expert Comment

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Suggested Courses

609 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