我有一个.txt文本文件,共1732行,每一行都有13个用逗号(,)间隔的数据,如下:
2010-8-27,16,59503,200,4.3,200,4.4,31.5,0,0.68,1003.8,31,48
2010-8-27,16,59504,192,2.9,192,3,32.5,0,0.65,1004.1,31,48
2010-8-27,16,59511,195,4.7,195,4.8,32.9,0,0.62,1004.3,31,48我想用TextStream对象对每一行数据进行逐一读取,每一个数据分别放入13个变量中,请问应该用什么方法?用open *.txt for input as #1方法打开该文本文件,然后用input #语句可实现对数据的逐一读取。但是我现在想用textstream对象来实现。请大家帮忙!谢谢大家!

解决方案 »

  1.   

    引用Microsoft Scripting RuntimeOption Explicit
    Dim f As New FileSystemObject
    Dim ts As TextStream
    Dim x As String
    Private Sub Command1_Click()
    Set ts = f.OpenTextFile("d:\test.txt")
    While Not ts.AtEndOfStream
        x = ts.ReadLine
        Debug.Print x
    Wend
    End Sub
      

  2.   

    大哥,你这个readline是每次对一行啊,我想每次读逗号前面的一个字符串:(
      

  3.   

    Private Sub Command1_Click()
        Dim f As New FileSystemObject
        Dim ts As TextStream
        Dim x As String
        Dim a() As String
        Dim i As Integer
        
        Set ts = f.OpenTextFile("e:\test9.txt")
        
        While Not ts.AtEndOfStream
            x = ts.ReadLine
            Debug.Print x
            a = Split(x, ",")
            
            For i = 0 To UBound(a)
                Debug.Print a(i)
            Next i
            
            '放到你的13个变量里
            'b1=a(0)
            'b2=a(1)
            '……
            'b13=a(12)
        Wend
    End Sub
      

  4.   

    谢谢了哈!
    split函数好用!