本帖最后由 lj2002aaa188 于 2010-09-03 12:55:09 编辑

解决方案 »

  1.   

    把读入的数据多个空格替换成1个,然后用split分离
    Input #1, strtempDo While InStr(strtemp, "  ") > 0
        strtemp = Replace(strtemp, "  ", " ")
    Loop
      

  2.   

    楼上方法不错啊,
    之前我也遇到这种情况,我的处理办法是先导入excel中再从excel中读取,现在看来太麻烦了
      

  3.   


    晕,csdn把空格吞了
    Input #1, strtempDo While InStr(strtemp, "  ") > 0        '直到没有两个空格
        strtemp = Replace(strtemp, "  ", " ")  '把两个空格替换成1个空格
    Loop
      

  4.   

    这个是将文本文件的内容整个读入,然后替换掉多余空格,再用split分割的话,返回的数组下标规律性不强。如果需要读一行数据,在调用其它计算函数,然后再读1行数据再调用相关函数的的话,那一次性读入的方式是否就不可取,还有其它方法读数据吗?
      

  5.   

    就是让你读一行,处理一行的*********************
    Public Sub red_station()
    Dim i, j, n As Integer
    Dim a() As String, b() As String, c() As Single, d() As Single,e() As Single
    dim strTemp as stringfile_name = "d:\1.txt"
    Open file_name For Input As #1
    Input #1, n  '读入第一行(10个站点)
    ReDim a(n-1) As String, b(n-1) As String, c(n-1) As Single,d(n-1) As Single,e(n-1) As Single
    For i = 0 To n - 1
       Input #1, strtempDo While InStr(strtemp, "  ") > 0        '直到没有两个空格
        strtemp = Replace(strtemp, "  ", " ")  '把两个空格替换成1个空格
    Loop
      Input #1, a(i), b(i),c(i),d(i),e(i)
    Next
    Close #1
    End Sub
      

  6.   

    就是让你读一行,处理一行的*********************
    Public Sub red_station()
    Dim i, j, n As Integer
    Dim a() As String, b() As String, c() As Single, d() As Single,e() As Single
    dim strTemp as string
    dim t() as stringfile_name = "d:\1.txt"
    Open file_name For Input As #1
    Input #1, n '读入第一行(10个站点)
    ReDim a(n-1) As String, b(n-1) As String, c(n-1) As Single,d(n-1) As Single,e(n-1) As SingleFor i = 0 To n - 1
      Input #1, strtemp  Do While InStr(strtemp, "  ") > 0 '直到没有两个空格
          strtemp = Replace(strtemp, "  ", " ") '把两个空格替换成1个空格
      Loop
      
      t=split(strtemp," ")
      redim preserve t(4)
      a(i)=t(0)
      b(i)=t(1)
      c(i)=t(2)
      d(i)=t(3)
      e(i)=t(4)
    Next
    Close #1
    End Sub