本文介绍了有没有什么办法来检查,看看是否VBScript函数的定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能只是一厢情愿的想法......
This is probably just wishful thinking...
有没有什么办法来检查,看是否ASP / VBScript函数是调用它之前定义的?
Is there any way to check to see if an ASP/VBScript function is defined before calling it?
推荐答案
这是因为它依赖于已经设置为On错误继续下一步做一个稍微哈克方式,但你可以做这样的事情:
It's a slightly hacky way to do it as it relies on having set "On Error Resume Next", but you could do something like this:
On Error Resume Next
Dim objRef1, objRef2
Set objRef1 = GetRef("DoStuff1")
If objRef1 Is Nothing Then
Call objRef1
Else
MsgBox "DoStuff1 is not defined!"
End If
Set objRef2 = GetRef("DoStuff2")
If objRef2 Is Nothing Then
MsgBox "DoStuff2 is not defined!"
Else
Call objRef2
End If
Sub DoStuff1
MsgBox "DoStuff1!"
End Sub
要GetRef呼叫将产生如果子异常或功能,您正在试图获得一个指向不存在(这是这里的情况与DoStuff2)。然后,您可以检查是否如预期的基准设置。
The call to GetRef will generate an exception if the sub or function you're trying to get a pointer to does not exist (as is the case here with DoStuff2). You can then check if the reference was set as expected.
这篇关于有没有什么办法来检查,看看是否VBScript函数的定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!