如何把txt文件中的多个数据,分别读取到多个text控件中显示出来?
txt文件中数据排列如: 
  AO
  BO
  C0
  01
  05
文本中每一行只有2个数字,
使用一个command控件,6个text控件,
要求点击一次command控件使txt文件中每一行的数字分别在6个text文本框中显示出来。

解决方案 »

  1.   

    Dim fileNum As Integer,temp as string
    fileNum = FreeFile
    Open "文本文件.txt" For Input As #fileNum
    i=0
    While Not EOF(fileNum)
        Line Input #fileNum, temp
        j=i+1
        Select Case i
            Case 1:text1.text = temp
            Case 2:text2.text = temp
            Case 3:text3.text = temp
            Case 4:text4.text = temp
            Case 5:text5.text = temp
            Case 6:text6.text = temp
        End Select
        i=(i+1) mod 7
    Wend
    Close #fileNum
      

  2.   

    Option ExplicitPrivate Sub Command1_Click()
        Dim a$(1 To 6), i%, j%
        Open "D:\1.txt" For Input As #1
        i = 0
        While Not EOF(1)
            i = i + 1
            Line Input #1, a(i)
        Wend
        
        For j = 1 To i
            Text1(j - 1).Text = a(j)
        Next
        
        
        Close #1
    End Sub
      

  3.   

        Dim i As Long, s As String, a() As String    Open "C:\0.txt" For Binary As #1    
        s = StrConv(InputB(LOF(1), #1), vbUnicode)
        a = Split(s, vbCrLf)
        For i = 1 To UBound(a) + 1
            Me.Controls("Text" & i).Text = a(i - 1)
        Next
        Close #1
      

  4.   

    有一点小错误,改正一下
    Dim fileNum As Integer,temp as string
    fileNum = FreeFile
    Open "文本文件.txt" For Input As #fileNum
    i=0
    While Not EOF(fileNum)
      Line Input #fileNum, temp
      j=i+1
      Select Case j
      Case 1:text1.text = temp
      Case 2:text2.text = temp
      Case 3:text3.text = temp
      Case 4:text4.text = temp
      Case 5:text5.text = temp
      Case 6:text6.text = temp
      End Select
      i=(i+1) mod 7
    Wend
    Close #fileNum
      

  5.   

    行数没有规定,TXT文本中每一行都只有两个数字。谢谢各位高手!
      

  6.   

    没有回复的话,那怎么把数据放到六个Txtbox里面呢?那不就间接说明只有六行吗?