PDA

Click to See Complete Forum and Search --> : Listbox


Hutty
Jan 10th, 2000, 04:18 AM
How can I populate a listbox with data from a text file? OR How can populate a listbox with multiple columns of data? I want to reference the index of the listbox items.
I thought the syntax List1.additem "c:\list1.txt" would work, but it didn't.

Thanks!

Aaron Young
Jan 10th, 2000, 04:23 AM
Try something like:

Private Sub Form_Load()
Dim iFile As Integer
Dim sData As String

iFile = FreeFile
Open "C:\List1.txt" For Input As iFile
sData = Input(LOF(iFile), iFile)
Close iFile
While Len(sData)
If InStr(sData, vbCrLf) Then
List1.AddItem Left$(sData, InStr(sData, vbCrLf) - 1)
sData = Mid$(sData, InStr(sData, vbCrLf) + 2)
Else
List1.AddItem sData
sData = ""
End If
Wend
End Sub


------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com