最近的一些应用需要判断是否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")
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
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