Results 1 to 11 of 11

Thread: Pulling INI data..

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    94

    Pulling INI data..

    I'm trying to create a different way to pull data from a ini file. Rather than only pulling the values, i wish to pull everything under the [name] until it reaches another [name].

    Example:

    [namehere]
    1=a
    2=b
    3=c
    etc...
    [name2here]

    i wish to pull the following:
    1=a
    2=b
    3=c
    etc..

    can it be done? i hate working with txt files

  2. #2
    Frenzied Member Inuyasha1782's Avatar
    Join Date
    May 2005
    Location
    California, USA
    Posts
    1,035

    Re: Pulling INI data..

    It's not the best way, but an example anyway:

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim ff, x, y As Integer
    3.     Dim entrys(100, 100) As String
    4.  
    5.  
    6.     ff = FreeFile
    7.  
    8.     Open "C:\test.ini" For Input As ff
    9.     Do Until EOF(ff)
    10.         Line Input #ff, strLine
    11.  
    12.         If InStr(1, strLine, "[") Then
    13.             x = 0
    14.            If strLine <> vbNull Then entrys(y + 1, x) = strLine
    15.             y = y + 1
    16.         Else
    17.             If strLine <> vbNull Then entrys(y, x + 1) = strLine
    18.             x = x + 1
    19.         End If
    20.  
    21.     Loop
    22.  
    23.     Close #ff
    24.  
    25.     MsgBox entrys(1, 0)
    26.     MsgBox entrys(1, 1)
    27.  
    28. End Sub

    That would put everything into an array. Each name would be in (1, 0) - (2, 0) - (3, 0) and their child entrys would be the second dimension like (1, 1) - (2, 1). I'm sure there is a better way, but it works
    Age - 15 ::: Level - Advanced
    If you find my post useful please ::Rate It::


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    94

    Re: Pulling INI data..

    yah it works, but i'm going to need something that starts at the [name] that i want, and finish at the next [name] but pull all the info between the two. The [name] could be on any line, so it would be very hard for me to find using that code.

  4. #4
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Pulling INI data..

    Try this

    VB Code:
    1. Dim StartWord As String
    2. Dim FinishWord As String
    3. Dim StrData As String
    4.  
    5. StartWord = "[namehere]"
    6. FinshWord = "[name2here]"
    7.  
    8. Open FileName For Input As #1
    9.     StrData = Input(LOF(1), 1)
    10.     strt = InStr(1, StrData, StartWord) + Len(StartWord)
    11.     fnsh = InStr(1, StrData, FinshWord)
    12.     MsgBox Mid(StrData, strt, fnsh - strt)
    13. Close #1
    Last edited by Andrew G; Jan 29th, 2006 at 07:14 AM.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    94

    Re: Pulling INI data..

    a bit buggy. heres the thing though. i will only know the name of the info that i need to pull. The name that it should stop at is random. So the only way i can think of stopping it, is simply using a [ to hault.

  6. #6
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Pulling INI data..

    Try this (not tested)

    VB Code:
    1. Dim StartWord As String
    2. Dim FinishWord As String
    3. Dim StrData As String
    4.  
    5. StartWord = "]"
    6. FinshWord = "["
    7.  
    8. Open FileName For Input As #1
    9.     StrData = Input(LOF(1), 1)
    10.     strt = InStr(1, StrData, StartWord)
    11.     fnsh = InStr(strt, StrData, FinshWord)
    12.     MsgBox Mid(StrData, strt, fnsh - strt)
    13. Close #1

  7. #7

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    94

    Re: Pulling INI data..

    Quote Originally Posted by Andrew G
    Try this (not tested)

    VB Code:
    1. Dim StartWord As String
    2. Dim FinishWord As String
    3. Dim StrData As String
    4.  
    5. StartWord = "]"
    6. FinshWord = "["
    7.  
    8. Open FileName For Input As #1
    9.     StrData = Input(LOF(1), 1)
    10.     strt = InStr(1, StrData, StartWord)
    11.     fnsh = InStr(strt, StrData, FinshWord)
    12.     MsgBox Mid(StrData, strt, fnsh - strt)
    13. Close #1
    Hey that works out pretty good. But by looking at it, there wouldn't be a way to check to see if there is a "=" on the same line that the finishword is on, because all of the data is in one big chunk. Would there be another way of doing this, maybe using split?

  9. #9

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    94

    Re: Pulling INI data..

    Quote Originally Posted by RhinoBull
    Have you looked at the sample I posted? Don't try to re-invent the wheel...
    Yes, didn't have much time to fully read it though. give me a sec
    Last edited by Fragment; Jan 30th, 2006 at 09:51 PM.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    94

    Re: Pulling INI data..

    ehh bit buggy, couldn't really tell if that was even what i'm looking for. i could only get it to pull the info to the left of the '=' without having it lock up on me.

    shrug

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