|
|
Title | Load a ListBox using the lines in a file using Split |
Keywords | additem, ListBox, line, file, Split |
Categories | Controls |
|
|
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
|
|
|
|
|
|