Type mismatch: '[string: ""]'
I receive the following error when there is no value for querystring. (I mean like index.asp?ID=).
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: ""]'
index.asp, line 10
I tried converting NULL value to something else with the following code. It did not work.
MEMBERID = Request.QueryString("ID")
If MEMBERID = "" or MEMBERID = 0 Then
MEMBERID开发者_高级运维 = Session("MEMBERID")
End If
OK, you're getting the parameter ID from the QueryString and checking if it's empty or zero, right? So, you should do something like:
MemberId = Request.QueryString("ID")
'*
'* Check for other than numbers just to be safe
'*
If (MemberId = "" Or Not IsNumeric(MemberId)) Then
MemberId = Session("MemberId")
End If
'*
'* We can't add this check on the above if because
'* in classic ASP, the expression is evaluated as a whole
'* which would generate an exception when converting to Int
'*
If (CInt(MemberId) = 0) Then
MemberId = Session("MemberId")
End If
If you want to convert a null to an empty string, use the string concatenation operator &
:
MEMBERID = Request.QueryString("ID") & ""
Well, in my case, the code was like this:
if TRIM(variavel) <> "0" then
variavel = "1"
end if
And the "default" solution here where i work is:
if isNull(variavel) then
variavel = "1"
end if
I hope it helps.
Check for Nothing:
IF Request.QueryString("ID") IS Nothing Then
...
End If
Here is how I would do this:-
dim memberID : memberID = Request.QueryString("ID")
if memberID <> "" then memberID = CLng(memberID)
if memberID = Empty then memberID = Session("MemberID")
The QueryString item property returns either an Empty
or a String
. It will never return a integer.
If memberID is not parsable as an integer then this code will error. However, if the value on ID is supposed to be an integer but is actually something else then I would want it to fail.
Empty
compares as equal to both zero-length string and numeric 0.
精彩评论