VC++6.0 profile 结果制作 Excel表格

本文介绍了一种使用VBA从文本文件中读取并解析性能profile数据的方法,并将其导入Excel进行进一步分析。通过编写特定的VBA代码,能够逐行读取文本中的数值和函数名称,自动填充到Excel表格中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

profile 的结果是个文本信息,例如

        .....

       0.075   0.0    30496.312  40.2        1 _decode_one_frame (image.obj)
       0.075   0.0        0.142   0.0      236 _readSyntaxElement_FLC (vlc.obj)
       0.070   0.0       38.906   0.1       40 _get_mem4Dshort (memalloc.obj)
       0.068   0.0        0.068   0.0       39 _decode_poc (header.obj)
       0.067   0.0        0.067   0.0      236 _GetBits (vlc.obj)

        ......

这些信息是有规律的,我把类似的信息保存在文本文件中,起名为result.txt,打开Excel,进入Visual Basic编辑器,编写VBA代码,如下:

Dim s As String
' 执行函数入口
Public Sub Analyse()
    filespec = "C:/result.txt" '按实际路径填写
    Const ForReading = 1, ForWriting = 2, ForAppending = 3
    Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
    Dim fs, f, str
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(filespec)
    Set ts = f.OpenAsTextStream(ForReading, TristateFalse)
    s = ts.ReadLine
    j = 1
    While s <> ""
        i = 1
        While s <> ""
            str = Chr(Asc("A") + i - 1) & CStr(j)
            wd = GetWord()
            If wd <> "" Then
                Range(str) = wd
            End If
            i = i + 1
        Wend
        If Not ts.AtEndOfStream Then
            s = ts.ReadLine
        Else
            s = ""
        End If
        j = j + 1
    Wend
    ts.Close
End Sub


'从字符串读取词

Public Function GetWord() As String
    i = 1
    While (Mid(s, i, 1) = " " And Mid(s, i, 1) <> "")
        i = i + 1
    Wend
    While (Mid(s, i, 1) <> " " And Mid(s, i, 1) <> "")
        GetWord = GetWord & Mid(s, i, 1)
        i = i + 1
    Wend
    If Len(s) - i > 0 Then
        s = Right(s, Len(s) - i)
    Else
        s = ""
    End If
End Function

匆匆写就,比较笨的方法,请行家批评指正

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值