Confusing confitional statement

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Re: Confusing confitional statement

    ok.. so if thats the issue, then the original

    if optiondone<>"" then response.write "" else response.write "<br />"

    because if it wasnt "" then that statement becomes true hence it should not
    have worked.. yet it does...

    Rafe



    "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    news:OkqzeQfVDHA.2000@TK2MSFTNGP09.phx.gbl...
    > Maybe optiondone is NULL, which is not the same as ""?
    >
    >
    >
    > "Rafe Harwood" <rafe@harvardclose.co.uk> wrote in message
    > news:EOxVa.1156$CR5.70@newsfep3-gui.server.ntli.net...
    > > I have a problem with an if statement which runs along the lines of ...
    > >
    > > do while not rst.eof
    > > if optiondone<>rst.fields("description") then response.write
    > "<div
    > > class=""littleandorange""
    > > style=""font-size:90%"">"&rst.fields("description")&"</div>"
    > > optiondone=rst.fields("description")
    > > if optiondone<>"" then response.write "" else response.write
    > "<br
    > > />"
    > > response.write "<form action="""&myurl&"?"&myqs&"""
    > > method=""post""><input type=""hidden"" name=""add""
    > > value="""&rst.fields("itemID")&""" /><input type=""image"" id=""submit""
    > > src=""/images/select.gif"" alt=""Add "&rst.fields("name")&" at
    > > "&formatcurrency(rst.fields("price"),2)&" to your order"" /> -
    > > "&rst.fields("name")&" -
    "&formatcurrency(rst.fields("price"),2)&"</form>"
    > > rst.movenext
    > > loop
    > >
    > > This version with the weird if optiondone<>"" then response.write
    > ""
    > > else response.write "<br />" works fine.. to my mind that would
    mean
    > > that exactly the same should work if used the other way round and using
    =
    > > instead of <> and the basically non-existant response, looking for a
    > > negative to produce the required action.
    > >
    > > If I try this however..
    > >
    > > do while not rst.eof
    > > if optiondone<>rst.fields("description") then response.write
    > "<div
    > > class=""littleandorange""
    > > style=""font-size:90%"">"&rst.fields("description")&"</div>"
    > > optiondone=rst.fields("description")
    > > if optiondone="" then response.write "<br />"
    > > response.write "<form action="""&myurl&"?"&myqs&"""
    > > method=""post""><input type=""hidden"" name=""add""
    > > value="""&rst.fields("itemID")&""" /><input type=""image"" id=""submit""
    > > src=""/images/select.gif"" alt=""Add "&rst.fields("name")&" at
    > > "&formatcurrency(rst.fields("price"),2)&" to your order"" /> -
    > > "&rst.fields("name")&" -
    "&formatcurrency(rst.fields("price"),2)&"</form>"
    > > rst.movenext
    > > loop
    > >
    > > then it falls over and the break is not written...
    > >
    > > Any ideas as to why a negative response works yet a positive fails?
    > >
    > > Rafe
    > >
    > >
    >
    >

    Rafe Harwood Guest

  2. Similar Questions and Discussions

    1. A very confusing question ?
      As all of the people told that assemblies are of three types, Private, Public & Satellite. But I think these are of only two types: 1. Single...
    2. URL.CFID confusing sessions
      Where do I start? When going to any of our web sites, the home page comes up and i the URL I have a CFID and CFTOKEN URL vars. On this same home...
    3. Deployment of a Site Confusing!
      I have tried several ways to sync up my Developement and test servers, but it is not updating my test server. I understand there are three...
    4. I'm confusing myself
      Hiyer, I've used Flash for creating CD-Roms but Ive been asked to design a web site. I'm now getting myself really confused too. I want to add in...
    5. confusing error
      I am getting a confusing 'object expected' error in IE when this script executes, but I can't figure out why. It stops all other scripts on my...
  3. #2

    Default Re: Confusing confitional statement

    Comparing anything to Null returns Null, not True or False.

    Far better is to check the length of optiondone:

    if len(optiondone) > 0 then 3
    etc.

    HTH,
    Bob Barrows


    Rafe Harwood wrote:
    > ok.. so if thats the issue, then the original
    >
    > if optiondone<>"" then response.write "" else response.write "<br />"
    >
    > because if it wasnt "" then that statement becomes true hence it
    > should not have worked.. yet it does...
    >
    > Rafe
    >
    >
    >
    > "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    > news:OkqzeQfVDHA.2000@TK2MSFTNGP09.phx.gbl...
    >> Maybe optiondone is NULL, which is not the same as ""?
    >>
    >>
    >>
    >> "Rafe Harwood" <rafe@harvardclose.co.uk> wrote in message
    >> news:EOxVa.1156$CR5.70@newsfep3-gui.server.ntli.net...
    >>> I have a problem with an if statement which runs along the lines of
    >>> ...
    >>>
    >>> do while not rst.eof
    >>> if optiondone<>rst.fields("description") then
    >>> response.write "<div class=""littleandorange""
    >>> style=""font-size:90%"">"&rst.fields("description")&"</div>"
    >>> optiondone=rst.fields("description")
    >>> if optiondone<>"" then response.write "" else
    >>> response.write "<br />"
    >>> response.write "<form action="""&myurl&"?"&myqs&"""
    >>> method=""post""><input type=""hidden"" name=""add""
    >>> value="""&rst.fields("itemID")&""" /><input type=""image""
    >>> id=""submit"" src=""/images/select.gif"" alt=""Add
    >>> "&rst.fields("name")&" at "&formatcurrency(rst.fields("price"),2)&"
    >>> to your order"" /> - "&rst.fields("name")&" -
    >>> "&formatcurrency(rst.fields("price"),2)&"</form>"
    >>> rst.movenext loop
    >>>
    >>> This version with the weird if optiondone<>"" then
    >>> response.write "" else response.write "<br />" works fine.. to
    >>> my mind that would mean that exactly the same should work if used
    >>> the other way round and using = instead of <> and the basically
    >>> non-existant response, looking for a negative to produce the
    >>> required action.
    >>>
    >>> If I try this however..
    >>>
    >>> do while not rst.eof
    >>> if optiondone<>rst.fields("description") then
    >>> response.write "<div class=""littleandorange""
    >>> style=""font-size:90%"">"&rst.fields("description")&"</div>"
    >>> optiondone=rst.fields("description")
    >>> if optiondone="" then response.write "<br />"
    >>> response.write "<form action="""&myurl&"?"&myqs&"""
    >>> method=""post""><input type=""hidden"" name=""add""
    >>> value="""&rst.fields("itemID")&""" /><input type=""image""
    >>> id=""submit"" src=""/images/select.gif"" alt=""Add
    >>> "&rst.fields("name")&" at "&formatcurrency(rst.fields("price"),2)&"
    >>> to your order"" /> - "&rst.fields("name")&" -
    >>> "&formatcurrency(rst.fields("price"),2)&"</form>"
    >>> rst.movenext loop
    >>>
    >>> then it falls over and the break is not written...
    >>>
    >>> Any ideas as to why a negative response works yet a positive fails?
    >>>
    >>> Rafe


    Bob Barrows Guest

  4. #3

    Default Re: Confusing confitional statement

    Ray at <%=sLocation%> wrote:
    > What's 3?
    >
    I SAID not to ask me that ... ;-)


    Bob Barrows Guest

  5. #4

    Default Re: Confusing conditional statement

    > >> "Rafe Harwood" <rafe@harvardclose.co.uk> wrote in message
    > >> news:EOxVa.1156$CR5.70@newsfep3-gui.server.ntli.net...
    > >>> I have a problem with an if statement which runs along the lines of
    > >>> ...
    > >>>
    > >>> do while not rst.eof
    > >>> if optiondone<>rst.fields("description") then
    > >>> response.write "<div class=""littleandorange""
    > >>> style=""font-size:90%"">"&rst.fields("description")&"</div>"
    > >>> optiondone=rst.fields("description")
    > >>> if optiondone<>"" then response.write "" else
    > >>> response.write "<br />"
    > >>> response.write "<form action="""&myurl&"?"&myqs&"""
    > >>> method=""post""><input type=""hidden"" name=""add""
    > >>> value="""&rst.fields("itemID")&""" /><input type=""image""
    > >>> id=""submit"" src=""/images/select.gif"" alt=""Add
    > >>> "&rst.fields("name")&" at "&formatcurrency(rst.fields("price"),2)&"
    > >>> to your order"" /> - "&rst.fields("name")&" -
    > >>> "&formatcurrency(rst.fields("price"),2)&"</form>"
    > >>> rst.movenext loop
    > >>>
    > >>> This version with the weird if optiondone<>"" then
    > >>> response.write "" else response.write "<br />" works fine.. to
    > >>> my mind that would mean that exactly the same should work if used
    > >>> the other way round and using = instead of <> and the basically
    > >>> non-existant response, looking for a negative to produce the
    > >>> required action.
    > >>>
    > >>> If I try this however..
    > >>>
    > >>> do while not rst.eof
    > >>> if optiondone<>rst.fields("description") then
    > >>> response.write "<div class=""littleandorange""
    > >>> style=""font-size:90%"">"&rst.fields("description")&"</div>"
    > >>> optiondone=rst.fields("description")
    > >>> if optiondone="" then response.write "<br />"
    > >>> response.write "<form action="""&myurl&"?"&myqs&"""
    > >>> method=""post""><input type=""hidden"" name=""add""
    > >>> value="""&rst.fields("itemID")&""" /><input type=""image""
    > >>> id=""submit"" src=""/images/select.gif"" alt=""Add
    > >>> "&rst.fields("name")&" at "&formatcurrency(rst.fields("price"),2)&"
    > >>> to your order"" /> - "&rst.fields("name")&" -
    > >>> "&formatcurrency(rst.fields("price"),2)&"</form>"
    > >>> rst.movenext loop
    > >>>
    > >>> then it falls over and the break is not written...
    > >>>
    > >>> Any ideas as to why a negative response works yet a positive fails?
    > >>>
    > >>> Rafe
    > > "Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
    > > news:OkqzeQfVDHA.2000@TK2MSFTNGP09.phx.gbl...
    > >> Maybe optiondone is NULL, which is not the same as ""?
    > Rafe Harwood wrote:
    > > ok.. so if thats the issue, then the original
    > >
    > > if optiondone<>"" then response.write "" else response.write "<br />"
    > >
    > > because if it wasnt "" then that statement becomes true hence it
    > > should not have worked.. yet it does...
    > >
    > > Rafe

    "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    news:uoVkVifVDHA.2040@TK2MSFTNGP10.phx.gbl...
    > Comparing anything to Null returns Null, not True or False.
    >
    > Far better is to check the length of optiondone:
    >
    > if len(optiondone) > 0 then 3
    > etc.
    >
    > HTH,
    > Bob Barrows
    ok.. after a little editing of the order of posts... and correcting the
    typo in the thread hehe

    Thanks Bob,
    That works for the negative response as if the size is over 0 then I do not
    want the break included, but it falls over when testing for a size <1 which
    would be the time to display the break.. hence

    if len(optiondone)<1 then write "<br />"

    which I suppose is the same thing as the null issue but not sure


    anyway, that statement also falls over...

    the way I just solved it was to check for a null value

    if isnull(optiondone) then write "<br />"

    still doesnt answer my question about the difference in checking which was
    my major bugbear.. but it solves the issue perfectly :O)
    thank you for the heads up Aaron :O)

    I didnt realise that setting the value of optiondone to "" in fact created a
    null and not "" which is obviously what happens, as optiondone is populated
    earlier in the results, but on checking for the null after setting it to ""
    the response comes back as true and the break displayed

    Rafe


    Rafe Harwood Guest

  6. #5

    Default Re: Confusing conditional statement

    Rafe Harwood wrote:
    > Thanks Bob,
    > That works for the negative response as if the size is over 0 then I
    > do not want the break included, but it falls over when testing for a
    > size <1 which would be the time to display the break.. hence
    >
    > if len(optiondone)<1 then write "<br />"
    You don't need this. Why are you doing this? A simple

    if len(optiondone)>0 then
    'do the stuff you need to do when optiondone contains a value
    else
    response.write "<br />"
    end if

    will suffice.
    >
    > which I suppose is the same thing as the null issue but not sure
    >
    >
    > anyway, that statement also falls over...
    >
    > the way I just solved it was to check for a null value
    >
    > if isnull(optiondone) then write "<br />"
    >
    > still doesnt answer my question about the difference in checking
    > which was my major bugbear.. but it solves the issue perfectly :O)
    > thank you for the heads up Aaron :O)
    >
    > I didnt realise that setting the value of optiondone to "" in fact
    > created a null and not ""
    It doesn't. "" is an empty string. It is NOT Null. Try this:

    optiondone = ""
    if isnull(optiondone) then
    response.write "optiondone contains Null"
    else
    response.write "opriondone contains an empty string"
    end if
    > which is obviously what happens, as
    > optiondone is populated earlier in the results, but on checking for
    > the null after setting it to "" the response comes back as true and
    > the break displayed
    >
    Are you sure??? Your code is written in a very confusing manner (in fact, I
    skipped your post the first time since I did not feel like digging into
    it) - no formatting or white-space to improve its readability. I suppose it
    could be your newsreader doing this... I suspect you may be missing
    something, but again, I don't feel like digging into your code. Sorry.

    Bob Barrows


    Bob Barrows Guest

  7. #6

    Default Re: Confusing conditional statement


    "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    news:#3iP8TgVDHA.3332@tk2msftngp13.phx.gbl...
    > Rafe Harwood wrote:
    > > Thanks Bob,
    > > That works for the negative response as if the size is over 0 then I
    > > do not want the break included, but it falls over when testing for a
    > > size <1 which would be the time to display the break.. hence
    > >
    > > if len(optiondone)<1 then write "<br />"
    >
    > You don't need this. Why are you doing this? A simple
    >
    > if len(optiondone)>0 then
    > 'do the stuff you need to do when optiondone contains a value
    > else
    > response.write "<br />"
    > end if
    >
    > will suffice.
    >
    > >
    > > which I suppose is the same thing as the null issue but not sure
    > >
    > >
    > > anyway, that statement also falls over...
    > >
    > > the way I just solved it was to check for a null value
    > >
    > > if isnull(optiondone) then write "<br />"
    > >
    > > still doesnt answer my question about the difference in checking
    > > which was my major bugbear.. but it solves the issue perfectly :O)
    > > thank you for the heads up Aaron :O)
    > >
    > > I didnt realise that setting the value of optiondone to "" in fact
    > > created a null and not ""
    >
    > It doesn't. "" is an empty string. It is NOT Null. Try this:
    >
    > optiondone = ""
    > if isnull(optiondone) then
    > response.write "optiondone contains Null"
    > else
    > response.write "opriondone contains an empty string"
    > end if
    >
    > > which is obviously what happens, as
    > > optiondone is populated earlier in the results, but on checking for
    > > the null after setting it to "" the response comes back as true and
    > > the break displayed
    > >
    > Are you sure??? Your code is written in a very confusing manner (in fact,
    I
    > skipped your post the first time since I did not feel like digging into
    > it) - no formatting or white-space to improve its readability. I suppose
    it
    > could be your newsreader doing this... I suspect you may be missing
    > something, but again, I don't feel like digging into your code. Sorry.
    >
    > Bob Barrows
    Ooops.. please excuse the mistake..

    the center of the code goes

    optiondone=rst.fields("description")
    if isnull(optiondone) then write "<br />"

    so it is in fact getting a null from the database

    Hmmm.. a cup of tea might be in order here

    And yes I am using Outlook Express.. and to the people in here who have a
    problem with it, Im really not to bothered.. helping and getting help
    matters not what tools are used to achieve that :O)

    Rafe


    Rafe Harwood Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139