Results 1 to 4 of 4

Thread: [RESOLVED] Add section names of a ini file to a combobox

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [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 ?
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    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)
    Last edited by DataMiser; Dec 6th, 2014 at 11:21 AM.

  3. #3

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  4. #4
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width