Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleRead all of the values in an INI file
DescriptionThis example shows how to read all of the values in an INI file in Visual Basic 6. It uses Line Input to read the lines and parses them.
KeywordsINI file, INI, initialization file
CategoriesFiles and Directories, Strings, Software Engineering
 
The prorgam uses Line Input to read each line int he INI file. It examines the first character of each line for the "[" character that indicates a section header. For other lines, it uses InStr to search for the "=" character that separates names and values.
 
Private Sub cmdRead_Click()
Dim fnum As Integer
Dim one_line As String
Dim pos As Integer

    fnum = FreeFile
    Open txtFileName.Text For Input As fnum

    Do While Not EOF(fnum)
        ' Read a line.
        Line Input #fnum, one_line

        ' See what it is.
        If Left$(one_line, 1) = "[" Then
            ' Section heading.
            lstValues.AddItem "Section: " & _
                Mid$(one_line, 2, Len(one_line) - 2)
        ElseIf InStr(one_line, "=") > 0 Then
            pos = InStr(one_line, "=")
            lstValues.AddItem "    " & _
                Left$(one_line, pos - 1) & _
                " (" & _
                Mid$(one_line, pos + 1) & _
                ")"
        Else
            lstValues.AddItem "    " & one_line
        End If
    Loop

    Close fnum
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated