IsNull bug in ASP?

B

Bob Cottis

I am getting wierd behaviour with IsNull in ASP. I am
passing a string (which may be null) to a function. When
the string is null, IsNull seems to return false the
first time it is called, then True the second time. The
code follows, am I doing something wrong, or is this a
bug?

Bob

function unquote(st) 'make database string suitable for
output
'#################
Dim test, test2
test = IsNull(st)
test2 = IsNull(st)
if test then
unquote=st
exit function
end if
response.write("In unquote st = " & st & "; isNull(st)
=" & IsNull(st) & "; " & test & "; " & test2 & "<br>")
'if st is null, test is false, but test2 is true
st = replace(st, "&", "&")
st = replace(st, "'", "'")
st = replace(st, """, chr(34))
st = replace(st, "<br>", chr(13) & chr(10))
unquote = st
end function
 
E

Evertjan.

Bob Cottis wrote on 15 okt 2003 in
microsoft.public.inetserver.asp.general:
I am
passing a string (which may be null)

There is no such thing as a "null string" in vbs.

st = null is not a atring, so you cannot do replaces on it.

st = "" is an empty string, not a null, so:
isnull("") gives true

Perhaps you could, dependng on your application,
change the null variable to an empty string:

if isnull(st) then st = ""

?
 
W

WIlliam Morris

A much safer method than relying on null values (which can cause havoc with
outputing a recordset, for instance):

If Len(Trim(MyPossiblyNullValue & " ")) = 0
'--- stuff here
End If

- Wm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top