[thelist] Other ways to check for null

Matt Warden mwarden at gmail.com
Mon Nov 14 12:34:45 CST 2005

On 11/14/05, Mark Rees <mrees at itsagoodprice.com> wrote:
> > if not isnull(rs("num_bedrooms")) or trim(rs("num_bedrooms")) <> "" then
> >            response.write("<b>Bedrooms:</b> " & rs("num_bedrooms") &
> > "<br><br>"
> > end if
> >
> The logic is wrong here.
> You're basically saying (pseudocode):
>  if rs("num_bedrooms") is not null  or "" then...
> It can't be both those things, so it's always going to evaluate as true i.e.
> if it's null, then it's not ""

Just to clarify what Mark is saying:

if not isnull(rs("num_bedrooms")) or trim(rs("num_bedrooms")) <> "" then

is logically equivalent to:

if not (isnull(rs("num_bedrooms")) and trim(rs("num_bedrooms")) = "") then


if (not A or not B) then <==> if not (A and B) then

in this case it makes no sense because A and B cannot be true at the
same time. So, you're essentially saying:

if (not false) then <==> if (true) then

It should be clear now why it is always evaluating as true.

Nice catch, Mark.

Matt Warden
Miami University
Oxford, OH, USA

This email proudly and graciously contributes to entropy.

More information about the thelist mailing list