Solved

How to determine if a section exists in a ini file

Posted on 2014-12-05
13
144 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now