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
 
 
 
 
 
TitleLoad a ListBox using the lines in a file using Split
Keywordsadditem, ListBox, line, file, Split
CategoriesControls
 
Use the Input command to read the entire file. Use Split to break it into lines. Then add each line to the ListBox.
 
Private Sub cmdLoad_Click()
Dim fnum As Integer
Dim file_contents As String
Dim lines As Variant
Dim i As Integer

    ' Grab the file's contents.
    fnum = FreeFile
    Open txtFile.Text For Input As #fnum
    file_contents = Input$(LOF(fnum), #fnum)
    Close #fnum

    ' Split the lines apart.
    lines = Split(file_contents, vbCrLf)

    ' Load the list.
    lstLines.Clear
    For i = LBound(lines) To UBound(lines)
        lstLines.AddItem lines(i)
    Next i
End Sub
 
Formatted by Neil Crosby
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated