[RESOLVED] Add section names of a ini file to a combobox
I am opening a ini file as text
I want the sections added to a combobox without the braces[]
Code:
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
If FileExists(fName) Then
Open fName For Input As f
Do Until EOF(f)
Line Input #f, IniText
if initext = [] then
cboSections.additem Initext
l = l + 1
End If
Loop
Close #f
End If
example ini file with 2 sections
[20 5 spots bet 20 2 blocks]
TotWonLost=-9.5
TotalRuns=301
NuBigWins=3
WonLost=-9.5
[20 5 spots bet 20 3 blocks]
TotWonLost=-0.2
TotalRuns=50
NuBigWins=0
WonLost=-0.2
how can this be done ?
Re: Add section names of a ini file to a combobox
Code:
if initext = [] then
That of course would be invalid
Strings must be in quotes.
You could trim the input string then check the left character and the right character to see if they are "[" and "]" respectively
You could then use Mid$() to pull the string from between the [] i.e. NewString=Mid$(Oldstring,2,len(oldstring)-2)
Re: Add section names of a ini file to a combobox
Thanks, just what i needed
i tried
looks like i need to spread reputation
Re: Add section names of a ini file to a combobox
if it helps.. a getbetween function will probably help you on this one:
Code:
'sSearch - the WHOLE text to search at
'sStart - the First string
'sStop - the Second string
Public Function GetBetween(ByRef sSearch As String, ByRef sStart As String, ByRef sStop As String, _
Optional ByRef lSearch As Long = 1) As String
On Local Error GoTo errHandler
lSearch = InStr(lSearch, sSearch, sStart)
If lSearch > 0 Then
lSearch = lSearch + Len(sStart)
Dim lTemp As Long
lTemp = InStr(lSearch, sSearch, sStop)
If lTemp > lSearch Then
GetBetween = Mid$(sSearch, lSearch, lTemp - lSearch)
End If
End If
errHandler: Exit Function
End Function
Example of usage:
Code:
dim my_string as string
my_string = Getbetween ("ABCD", "A","C")
Msgbox my_string
'guess the outcome of this one.