在 VBScript 中检查 NULL 时出错 [英] Error checking for NULL in VBScript
问题描述
我在经典 ASP 页面中有以下 VBScript:
I have the following VBScript in a Classic ASP page:
function getMagicLink(fromWhere, provider)
dim url
url = "magic.asp?fromwhere=" & fromWhere
If Not provider is Nothing Then ' Error occurs here
url = url & "&provider=" & provider
End if
getMagicLink = "<a target='_blank' href='" & url & "'>" & number & "</a>"
end function
我不断收到需要对象"的错误消息,上面写着If Not provider Is Nothing Then
.
I keep getting an "Object Required" error messager on the line that says If Not provider Is Nothing Then
.
该值要么是 NULL,要么不是 NULL,为什么我会收到这个错误?
Either the value is NULL, or it's not NULL, so why am I getting this error?
当我调用对象时,我传入 NULL,或者传入一个字符串.
When I invoke the object, I pass in either NULL, or I pass in a string.
推荐答案
从你的代码来看,provider
是一个变体或其他一些变量,而不是一个对象.
From your code, it looks like provider
is a variant or some other variable, and not an object.
Is Nothing
仅用于对象,但后来你说它是一个应该是 NULL 或 NOT NULL 的值,这将由 IsNull
处理.
Is Nothing
is for objects only, yet later you say it's a value that should either be NULL or NOT NULL, which would be handled by IsNull
.
尝试使用:
If Not IsNull(provider) Then
url = url & "&provider=" & provider
End if
或者,如果这不起作用,请尝试:
Alternately, if that doesn't work, try:
If provider <> "" Then
url = url & "&provider=" & provider
End if
这篇关于在 VBScript 中检查 NULL 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!