txt文件有几行数据,现想把每行作为list的一项,请问怎么实现?

解决方案 »

  1.   

    Set fso = CreateObject("scripting.filesystemobject")
        If Not fso.FileExists(App.Path & "\list.txt") Then
            MsgBox("找不到list.txt!")
        Exit Sub
        End If
        Chklist.Clear
        Set f = fso.OpenTextFile(App.Path & "\list.txt", 1)
        Do While Not f.AtEndOfStream
            Chklist.AddItem (f.ReadLine)
        Loop
        Set fso = Nothing
      

  2.   

    Dim Fname As String, Tmp As String
    If Right(App.Path, 1) <> "\" Then
        Fname = App.Path & "\list.txt"
    Else
        Fname = App.Path & "list.txt"
    End If
    If Dir(Fname) <> "" Then
        Open Fname For Input As #1
        Do While Not EOF(1)
            Line Input #1, Tmp
            List1.AddItem (Tmp)
        Loop
        Close
    End If
      

  3.   

    Dim lngFH As Long
        Dim strTemp As String
        lngFH = FreeFile
        '打开文本文件
        Open 要打开的文件路径 For Input As lngFH
        '读取文件并写入list
        Do While Not EOF(lngFH)
            Line Input #lngFH, strTemp
            list1.additem  strTemp
        Loop
        '关闭文件
        Close #lngFH