txt文件共有两组数,每一行两个,
例如
19.345 0.000
19.564 0.021
20.315 0.041怎么把他们读出来,第一个数放到一个数组里,第二个数放到另一个数组里。
谢谢

解决方案 »

  1.   

    读出txt数据,用split函数分开放不同数组
      

  2.   

    a(i)=split("19.345 0.000"," ")(0)
    b(i)=split("19.345 0.000"," ")(1)
      

  3.   

    请具体说说,split怎么用啊。谢谢
      

  4.   

    Dim Linedata As Double
        CDialog1.Filter = "textfiles(*.txt)|*.txt"
        CDialog1.ShowOpen
        If CDialog1.FileName = "" Then
            MsgBox "没有选择文件。"
            Exit Sub
        End If
        
        Erase Datacomy
        Erase Timex
        
        Open CDialog1.FileName For Input As #2
        For i = 1 To 1000
            Input #2, Linedata
            Timex(i) = Split(Linedata, " ")(0)
            Datacomy(i) = Split(Linedata, " ")(1)
        Next iClose #2我这样写对吗
      

  5.   

    第一行改成Dim Linedata As string
      

  6.   

    固定读入1000行吗,如果不是应该用do while    loop
      

  7.   

        Open "TESTFILE" For Input As #1 ' 打开文件。
        
        Do While Not EOF(1) ' 循环至文件尾。
            Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
            Debug.Print TextLine ' 在调试窗口中显示数据。
            ReDim Preserve a(i)
            ReDim Preserve b(i)
            a(i) = Split(TextLine, " ")(0)
            b(i) = Split(TextLine, " ")(1)
            i = i + 1
        Loop
        
        Close #1 ' 关闭文件。
      

  8.   

    Sub Drawdata()
    Dim i As Integer
       Picture1.DrawWidth = 1
       For i = 1 To Datacount
               DrawRealLine Picture1, Timex(i), Datacomy(i), Datacomy(i - 1)
       Next i
    End Sub为什么总是说下标越界呢?
    是怎么回事啊?
    请jhone99指教。
    Datacount是为本的行数
      

  9.   

    For i = 1 To Datacount
    ****************************
    for i = 0 to ubound(Datacomy)
      

  10.   

    不知道为什么总是说Datacomy(i)的下标越界
    是不是定义的不对
      

  11.   

    Private Sub Command1_Click()
        Dim TextLine As String
        Dim i As Integer
        Dim a() As String
        Dim b() As String    Open "TESTFILE" For Input As #1 ' 打开文件。    Do While Not EOF(1) ' 循环至文件尾。
            Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
            Debug.Print TextLine ' 在调试窗口中显示数据。
            ReDim Preserve a(i)
            ReDim Preserve b(i)
            a(i) = Split(TextLine, " ")(0)
            b(i) = Split(TextLine, " ")(1)
            i = i + 1
        Loop    Close #1 ' 关闭文件。End Sub
      

  12.   

    Private Sub Command1_Click()
        Dim TextLine As String
        Dim i As Integer
        Dim a() As String
        Dim b() As String    Open "TESTFILE" For Input As #1 ' 打开文件。    Do While Not EOF(1) ' 循环至文件尾。
            Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
            Debug.Print TextLine ' 在调试窗口中显示数据。
            ReDim Preserve a(i)
            ReDim Preserve b(i)
            a(i) = Split(TextLine, " ")(0)
            b(i) = Split(TextLine, " ")(1)
            i = i + 1
        Loop    Close #1 ' 关闭文件。End Sub
      

  13.   


    这种数据不用定义啊 用动态扩充就行了呀
    楼上的 
           ReDim Preserve a(i)
            ReDim Preserve b(i)
    就是动态扩充了数组另外数组是从0开始计数的 不是从1
      

  14.   

    这个貌似至少得用一个循环结构才行...我的方案:
    dim I as long,J as long,sTmp() as string
    dim sBuff as string,sLine() as string,Out()1 as string,Out2() as stringopen "xxx.txt" for binary as #1
        sbuff=space(eof(1))
        get #1,,sbuff
    close #1sline()=split(sbuff,vbcrlf)j=ubound(sline)
    redim out1(j)
    redim out2(j)for i=0 to j
        stmp()=split(sline(i)," ")    '这里的分隔符如果不是一个空格,就要自己确定一下    out1(i)=stmp(0)
        out2(i)=stmp(1)    debug.print out1(i),out2(i)
    next
      

  15.   

        Open CDialog1.FileName For Input As #2
        
        Do While Not EOF(2) ' 循环至文件尾。
            Line Input #2, Linedata ' 读入一行数据并将其赋予某变量。
            ReDim Preserve Timex2(i)
            ReDim Preserve Datacomy2(i)
            Lined = Split(Linedata)
            Timex2(i) = Lined(0)
            Datacomy2(i) = Lined(1)
            i = i + 1
            'Datacount = Datacount + 1
        Loop
        Close #2
        MsgBox i & "行"
        MsgBox "打开文件成功。"
        'Drawdata
        
        For j = 1 To 5                  
        DrawRealLine Picture1, Timex2(j), Datacomy2(j), Datacomy2(j - 1)
        Next j为什么这一句DrawRealLine Picture1, Timex2(j), Datacomy2(j), Datacomy2(j - 1)
    总是说我下标超界呢
      

  16.   

    For j = 0 To i - 1   
      

  17.   


    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        StatusBar1.Panels(1).Text = "X=" & X
        StatusBar1.Panels(2).Text = "Y=" & Y
    End Sub
      

  18.   

    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      StatusBar1.Panels(1).Text = "X=" & X
      StatusBar1.Panels(2).Text = "Y=" & Y
    End Sub