判断内存中是否存在指定函数

上一篇 / 下一篇  2009-12-23 00:00:31 / 个人分类:自动化测试

最近的一些应用需要判断是否VBS脚本运行中是否已经在内存中存在指定的函数,网上稍微找了一下,没发现好的方法,自己试了试,写了以下函数,试验结果通过。发出来共享,欢迎指正。
以下为VBScript脚本
 
Execute "sub a() : msgbox ""a"" : end sub"
MsgBox CheckMethodExist("a")
MsgBox CheckMethodExist("b")
Execute "sub b() : msgbox ""b~"" : end sub"
MsgBox CheckMethodExist("b")
 
' 判断内存中是否存在指定函数
'methodName:函数名,注意是字符串
Function CheckMethodExist(methodName)
    Dim boolResult
    boolResult = False
    On Error Resume Next
    boolResult = IsObject(GetRef(methodName))
    If Err.Number <> 0 Then
        boolResult = False
    End If
    On Error Goto 0
    CheckMethodExist = boolResult
End Function

TAG: vbs VBS 内存 函数

 

评分:0

我来说两句

chenyb85

chenyb85

大海无量。。。 QQ:20710378

日历

« 2024-04-17  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 18868
  • 日志数: 20
  • 建立时间: 2009-03-11
  • 更新时间: 2011-08-21

RSS订阅

Open Toolbar