假设文本内容格式为
12   22   23   23   34
13   34   34   34   34
则LISTVIEW控件显示为
XXX  XXX  XXX  XXX  XXX
12   22   23   23   34
13   34   34   34   34
XXX分别为控件的5个column headers
帮我把程序改下,谢谢
Private Sub Form_Load()
    Dim tpStr As String, i As Integer
    fileName = App.Path & "\test.txt"
    If Dir(fileName) <> "" Then
      '加载数据
      Open fileName For Input As #1
        Do While Not EOF(1)
          With ListView1.ListItems.Add()
            For i = 0 To 4
              Line Input #1, tpStr
              If i = 0 Then
                .Text = tpStr
              Else
                .SubItems(i) = tpStr
              End If
            Next i
          End With
        Loop
      Close #1
    End If
End Sub

解决方案 »

  1.   

    先要把那一排11 22 23 23 24用split函数分隔开才行吧。
    dim tplist(4)Do While Not EOF(1)
    line input #1,tpstr
    tplist=split (tpstr," ")  '不晓得你的空格数量固定不。或者用别的符号。
    With ListView1.ListItems.Add()
    For i = 0 To 4
    If i = 0 Then
                    .Text = tpStr
                  Else
                    .SubItems(i) = tpStr
                  End If
                Next i
              End With
            Loop
      

  2.   

    运行的时候,can't assign to array
      

  3.   

    刚才copy偷懒了。
    这个是没偷懒的。:)
    另外你的listview需要有5列。少了就出错。Private Sub Form_Load()
        Dim tpStr As String, i As Integer
        FileName$ = App.Path & "\test.txt"
        If Dir(FileName) <> "" Then
                Open FileName For Input As #1
    Do While Not EOF(1)
    Line Input #1, tpStr
    ReDim tplist(4) As String
    tplist = Split(tpStr, "   ") '不晓得你的空格数量固定不。或者用别的符号。
    With ListView1.ListItems.Add()
    For i = 0 To 4
                  If i = 0 Then
                   .Text = tplist(0)
                Else
                    .SubItems(i) = tplist(i)
                 End If
    Next i
    End With
            Loop
          Close #1
        End If
    End Sub