Results 1 to 2 of 2

Thread: Listbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153

    Post

    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!

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try something like:
    Code:
    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
    [email protected]
    [email protected]


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