有什么方法可以检查是否定义了 VBScript 函数? [英] Is there any way to check to see if a VBScript function is defined?

查看:30
本文介绍了有什么方法可以检查是否定义了 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 Error Resume Next",但你可以这样做:

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 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆