结果数据
序号 保留时间(min) 峰高 面积 名称 浓度
1 1.217 530 2511 co 1.0438
2 1.432 447 2582 co2 1.09809
3 1.674 358 2314 ch4 0.925743
4       1.264   256     2451    o2      0.326543
上面的是一个othergas.txt中的数据,怎么能获得CO.CO2,CH4,O2的浓度?
非常急用,希望各位大侠帮帮忙,小弟不胜感激。

解决方案 »

  1.   

    CO.CO2,CH4,O2的浓度?
    你的数据中哪里说到这几了?
      

  2.   

    Private Sub Command1_Click()
    Dim sGetRow As String
    Dim vdata As Variant    Open "othergas.txt" For Input As #1
            Do Until EOF(1)
                Line Input #1, sGetRow
                vdata = Split(sGetRow, Space(1))
                Debug.Print Trim(vdata(4))
            Loop
        Close #1
    End Sub
      

  3.   

    Private Sub Command1_Click()
        Dim s As String
        Dim x As Variant
        Dim CO As Single, CO2 As Single, CH4 As Single, O2 As Single
        Open "F:\xxxx.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, s
            If Len(s) > 10 Then
                Do While InStr(s, "  ") <> 0
                    s = Replace(s, "  ", " ")
                Loop
                x = Split(s, " ")
                Select Case UCase(x(4))
                    Case "CO"
                        CO = CSng(x(5))
                    Case "CO2"
                        CO2 = CSng(x(5))
                    Case "CH4"
                        CH4 = CSng(x(5))
                    Case "O2"
                        O2 = CSng(x(5))
                End Select
            End If
        Loop
        
        Debug.Print "CO浓度:"; CO
        Debug.Print "CO2浓度:"; CO2
        Debug.Print "CH4浓度:"; CH4
        Debug.Print "O2浓度:"; O2
    End Sub
      

  4.   

    没有啊。
    结果数据
    序号 保留时间(min) 峰高 面积 名称 浓度
    1 1.217 530 2511 co 1.0438
    2 1.432 447 2582 co2 1.09809
    3 1.674 358 2314 ch4 0.925743
    4       1.264   256     2451    o2      0.326543
    元数据就是这样
      

  5.   

    我贴的代码我自己测试了
    运行结果:
    CO浓度: 1.0438 
    CO2浓度: 1.09809 
    CH4浓度: .925743 
    O2浓度: .326543 
    楼主好好找找原因吧
      

  6.   

    你的文本文件里面,完全是用空格隔开的?还是有TAB符呢?
      

  7.   

    Private Sub Command1_Click()
        Dim s As String
        Dim x As Variant
        Dim CO As Single, CO2 As Single, CH4 As Single, O2 As Single
        Open "F:\xxxx.txt" For Input As #1
        Do While Not EOF(1)
            Line Input #1, s
            If Len(Trim(s)) > 10 Then
                s = Replace(s, vbTab, " ") '替换tab
                s = Replace(s, " ", " ") '替换全角空格
                Do While InStr(s, "  ") <> 0
                    s = Replace(s, "  ", " ")
                Loop
                x = Split(s, " ")
                Select Case UCase(x(4))
                    Case "CO"
                        CO = CSng(x(5))
                    Case "CO2"
                        CO2 = CSng(x(5))
                    Case "CH4"
                        CH4 = CSng(x(5))
                    Case "O2"
                        O2 = CSng(x(5))
                End Select
            End If
        Loop
        
        Debug.Print "CO浓度:"; CO
        Debug.Print "CO2浓度:"; CO2
        Debug.Print "CH4浓度:"; CH4
        Debug.Print "O2浓度:"; O2
    End Sub
      

  8.   

    Option Explicit
        Dim str As String
        Dim str1 As String
        Dim l As Integer
        Dim strSj() As String
        Dim a As Integer
    Private Sub Command1_Click()
        Open "c:\othergas.txt" For Input As #1
            Do While Not EOF(1)
                Input #1, str1
                'Print str1
                str = str & str1 & Chr(13) & Chr(10)
                l = l + 1
            Loop
        Close
        Text2 = str
        a = l
        Dim sj() As String
        Dim sj1() As String
        ReDim strSj(l)
        ReDim sj1(l, 6)
        Dim i As Integer
        Dim j As Integer
        l = 0
        Open "c:\othergas.txt" For Input As #1
            Do While Not EOF(1)
                Input #1, str1
                strSj(l) = str1
                sj = Split(strSj(l), " ")
                For i = 0 To UBound(sj)
                    sj1(l, i) = sj(i)
                Next
                str = str & str1 & Chr(13) & Chr(10)
                l = l + 1
            Loop
        Close
        For j = 1 To a - 1
            Print sj1(j, 4) & ": " & sj1(j, 5)
        Next
    End Sub
      

  9.   

    上述代码基于othergas.txt文件的格式是每个数据间有1个空格:序号 保留时间(min) 峰高 面积 名称 浓度
    1 1.217 530 2511 co 1.0438 
    2 1.432 447 2582 co2 1.09809 
    3 1.674 358 2314 ch4 0.925743 
    4 1.264 256 2451 o2 0.326543
      

  10.   

    结果数据
    序号 保留时间(min) 峰高 面积 名称 浓度
    1 1.217 530 2511 co 1.1264
    2 1.021 472 2314 co2 0.16541
    3 0.9123 624 6561 ch4 0.91265
    4 1.2654 465 1656 o2 0.8132结果数据
    序号 保留时间(min) 峰高 面积 名称 浓度
    1 1.217 530 2511 co 1.0438
    2 1.432 447 2582 co2 1.09809
    3 1.674 358 2314 ch4 0.92574
    4 1.231 531 1324 o2 0.4565结果数据 
    序号 保留时间(min) 峰高 面积 名称 浓度 
    1 1.217 530 2511 co 1.0438 
    2 1.432 447 2582 co2 1.09809 
    3 1.674 358 2314 ch4 0.925743 
    4      1.264  256    2451    o2      0.326543