我有如下文本文件:
5-09-11   1:00   25.6   25.6   25.1    49   14.1   0.0   ---  0.00   0.0   ---   25.6
05-09-11  10:00  26.6   26.7   26.4    66   19.7   0.0    S   0.00   0.4    S    26.6 
5-09-11  11:00   27.2   27.2   26.6    63   19.5   0.0   ---  0.00   0.0   ---   27.2 
想要读取每个子段的内容进行分析,不知如何把它读到变量中,请大家帮忙?

解决方案 »

  1.   

    打开文件后,用 line input 读取每一行到一个字符串中,然后用split函数把字符串变成子字符串数组,用空格作分割符,每一个数组元素对应一个子段。
      

  2.   

    读到变量,用Split函数分割到数组
      

  3.   

    Dim str1 As String
    Dim astr() As String
    Dim i as Long
    Open "c:\tmp.txt" For Input As 1
    str1 = Strconv(InputB$(LOF(1), 1), vbUnicode)
    astr = split(str1 , vbCrLf)
    For i=0 To Ubound(astr)
       strLine=astr(i)
       'strLine为一行的字符串
    Next
      

  4.   

    dim nFile as Integer, strTmp as String
        dim arTmp() as String
        nFile = FreeFile
        Open 文本文件全路径名 For Input As #nFile
        Do While Not EOF(nFile)
           Line Input #nFile, strTmp
           arTmp=Split(strTmp,分隔符)  '不知道你分隔符是空格还是TAB?
           分析该数组(arTmp(0)对应第一个字段,依次类推)
        Loop
        Close #nFile
      

  5.   

    '假设要得到多个空格分隔的内容
    Dim str1 As String
    Dim astr1() As String,astr2() As String
    Dim i as Long
    Open "c:\tmp.txt" For Input As 1
    str1 = Strconv(InputB$(LOF(1), 1), vbUnicode)
    astr1 = split(str1 , vbCrLf)'以回车换行符分割
    For i=0 To Ubound(astr1)
       strLine=astr1(i)
       'strLine为一行的字符串
       '多个空格替换为一个
       while not instr(strLine,"  ")=0
          strLine=replace(strLine,"  "," ")
          astr2=split(str1 , " ")
          '遍历astr2得到
       wend
    Next
      

  6.   

    搞错了,
    astr2=split(str1 , " ")
    应该放在循环外面
      

  7.   

    dim str as string
    dim arr() as string
    open "c:\txtfile.txt"  for input as #1
          line input #1,str
          arr=split(str," ")
         
          ....'处理过程close #1
      

  8.   

    arTmp(0)是第一个数,但arTmp(1)不是第二个数,artmp(3)是第二个数,第二数是时间,1:00到9:00是第二个数正常,但10:00时artmp(3)成了空值
      

  9.   

    使用Line Input取出每一行后,在用 viena(维也纳nn-实心木头人)的方法将多空格替换成单个空格应该不会有此问题:
       while not instr(strLine,"  ")=0
          strLine=replace(strLine,"  "," ")
          astr2=split(str1 , " ")
          '遍历astr2得到
       wend