(true = 1) returns false?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Evertjan.

    #16
    Re: (true = 1) returns false?

    Jason wrote on 06 jun 2006 in microsoft.publi c.inetserver.as p.general:[color=blue]
    > "roger" <mothland@btope nworld.com> wrote in message[color=green]
    >>
    >>
    >> Perhaps I am not understanding the problem
    >>
    >> dim b
    >>
    >> b = 1
    >> if b then Response.Write "true = 1"
    >> if b = true then Response.Write "but this doesn't work"
    >>
    >> gives me the result...
    >>
    >> true = 1
    >>
    >> Isn't that what you want?
    >>[/color]
    >
    > Yes. That's exactly what I want, but your example doesn't work that
    > way for me when I do it. For me, b = 0 evaluates to false, b = -1
    > evaluates to true, and if b equals any other number, then b is neither
    > true nor false. Are you sure that code works for you? I mean, did you
    > test it? Because if it does, I would be interested to know why it
    > works for you and not for me.[/color]

    Then why use the internal evaluation?

    Using your definition:

    if b = 0 then
    b = "is false"
    elseif b=-1 then
    b = "is true"
    else
    b = "is neither"
    end if



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Jason

      #17
      Re: (true = 1) returns false?


      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
      news:Xns97DA611 DAA9C9eejj99@19 4.109.133.242.. .[color=blue][color=green]
      >> works for you and not for me.[/color]
      >
      > Then why use the internal evaluation?
      >
      > Using your definition:
      >
      > if b = 0 then
      > b = "is false"
      > elseif b=-1 then
      > b = "is true"
      > else
      > b = "is neither"
      > end if
      >[/color]
      Yeah, I could do that....but I was looking for a solution that didn't
      involve changing my code every place I used 'if b = true then...'

      There is no solution that I am aware of so I did change my code from 'if
      b=true then...' to 'if CBool(b) = true then...' in every spot.


      Comment

      • Evertjan.

        #18
        Re: (true = 1) returns false?

        Jason wrote on 06 jun 2006 in microsoft.publi c.inetserver.as p.general:[color=blue]
        > "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message[color=green][color=darkred]
        >>> works for you and not for me.[/color]
        >>
        >> Then why use the internal evaluation?
        >>
        >> Using your definition:
        >>
        >> if b = 0 then
        >> b = "is false"
        >> elseif b=-1 then
        >> b = "is true"
        >> else
        >> b = "is neither"
        >> end if
        >>[/color]
        > Yeah, I could do that....but I was looking for a solution that didn't
        > involve changing my code every place I used 'if b = true then...'
        >
        > There is no solution that I am aware of so I did change my code from
        > 'if b=true then...' to 'if CBool(b) = true then...' in every spot.[/color]

        Since if then tests for true/false itself,
        I would not expect any difference in behavur between:

        if b = true then

        and

        if b then

        however,
        if you want to test for "true", "false" and "neither",
        my above code remains necassary, IMHO.


        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • Jason

          #19
          Re: (true = 1) returns false?

          >[color=blue]
          > Since if then tests for true/false itself,
          > I would not expect any difference in behavur between:
          >
          > if b = true then
          >
          > and
          >
          > if b then
          >
          > however,
          > if you want to test for "true", "false" and "neither",
          > my above code remains necassary, IMHO.
          >[/color]
          I don't think you understand the problem. ASP defines 0 as false and -1 as
          true, and everything else is neither. I wanted a way to make ASP define 1
          also as true, but we couldn't come up with one except to change code
          everywhere I needed that extra functionality.


          Comment

          • Evertjan.

            #20
            Re: (true = 1) returns false?

            Jason wrote on 06 jun 2006 in microsoft.publi c.inetserver.as p.general:
            [color=blue][color=green]
            >> if you want to test for "true", "false" and "neither",
            >> my above code remains necassary, IMHO.
            >>[/color]
            > I don't think you understand the problem.[/color]

            True.
            [color=blue]
            > ASP defines 0 as false and
            > -1 as true, and everything else is neither.[/color]

            Not true.

            ==============

            ASP is just the platform, and does not define.

            ==============

            ASP-VBscript does boolean TEST 0 as false and all other as true.
            [You could call that "define"]

            if 7 then response.write "TRUE"

            if NOT 0 then response.write "FALSE"

            VBscript does translate in a FORMULA true as -1, and false as 0

            response.write true ' shows True

            response.write 7 + true ' shows 6

            response.write 7 + false ' shows 7

            ===============

            ASP-JScript TESTS [boolean] 0 as false and other numbers as true,

            if (7) response.write( 'TRUE' );

            if (! 0) response.write( 'FALSE' );

            and does translate in a FORMULA true as 1, and false as 0

            response.write( 7 + true ); // 8

            [color=blue]
            > I wanted a way to make
            > ASP define 1 also as true, but we couldn't come up with one except to
            > change code everywhere I needed that extra functionality.
            >[/color]



            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • Bob Barrows [MVP]

              #21
              Re: (true = 1) returns false?

              Jason wrote:[color=blue][color=green]
              >>[/color]
              > I don't think you understand the problem. ASP defines 0 as false and
              > -1 as true, and everything else is neither.[/color]

              No, not quite. If an expression evaluates to 0, it is False. All other
              results are True*. Again, try:

              <%
              Response.Write CBool(-1)
              Response.Write CBool(0)
              Response.Write CBool(1)
              Response.Write CBool(2)

              %>
              Here is the result I get from this:
              TrueFalseTrueTr ue
              So you see that CBool(2) resulted in True. In fact, the only one that
              resulted in False was 0.

              In fact, try this:
              <%
              if (1+3) then
              Response.Write "<br>true"
              else
              Response.Write "<br>false"
              end if

              s="abcd"
              Response.Write "<BR>" & instr(s,"c")
              if instr(s,"c") then
              Response.Write "<BR>c is in abcd"
              else
              Response.Write "<BR>c is not in abcd"
              end if
              %>


              This is the real reason both Yes/No values from Access and bit values
              from SQL Server work well in vbscript/vb.
              I'm still not clear about why your boolean values from MySQL aren't
              working the same way.

              Bob Barrows

              *I realize I mistakenly said the reverse of this in my earlier message -
              my apologies.
              --
              Microsoft MVP -- ASP/ASP.NET
              Please reply to the newsgroup. The email account listed in my From
              header is my spam trap, so I don't check it very often. You will get a
              quicker response by posting to the newsgroup.


              Comment

              • Mike Brind

                #22
                Re: (true = 1) returns false?


                Bob Barrows [MVP] wrote:[color=blue]
                > Jason wrote:[color=green][color=darkred]
                > >>[/color]
                > > I don't think you understand the problem. ASP defines 0 as false and
                > > -1 as true, and everything else is neither.[/color]
                >
                > No, not quite. If an expression evaluates to 0, it is False. All other
                > results are True*.[/color]

                Interestingly, this is exactly the same in MySQL:
                (See BOOL,BOOLEAN subhead)


                --
                Mike Brind

                Comment

                • roger

                  #23
                  Re: (true = 1) returns false?


                  "Jason" <bigwheels16 hotmail> wrote in message
                  news:3sidnRgXm8 8gkxjZnZ2dnUVZ_ smdnZ2d@comcast .com...
                  [color=blue]
                  > Yes. That's exactly what I want, but your example doesn't work that way[/color]
                  for[color=blue]
                  > me when I do it. For me, b = 0 evaluates to false, b = -1 evaluates to
                  > true, and if b equals any other number, then b is neither true nor false.
                  > Are you sure that code works for you? I mean, did you test it? Because[/color]
                  if[color=blue]
                  > it does, I would be interested to know why it works for you and not for[/color]
                  me.

                  Very strange. And yes I did test it.

                  "if b then"
                  should test whether b is non-zero.

                  and

                  "if b = true then"
                  should test whether b is identical to the definition of the keyword "true",
                  which in VBScript is -1.

                  I remain mystified why this doesn't work for you.

                  --
                  roger


                  Comment

                  • Anthony Jones

                    #24
                    Re: (true = 1) returns false?


                    "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                    news:u9Jaz4aiGH A.1508@TK2MSFTN GP04.phx.gbl...[color=blue]
                    > Jason wrote:[color=green][color=darkred]
                    > >>[/color]
                    > > I don't think you understand the problem. ASP defines 0 as false and
                    > > -1 as true, and everything else is neither.[/color]
                    >
                    > No, not quite. If an expression evaluates to 0, it is False. All other
                    > results are True*. Again, try:
                    >
                    > <%
                    > Response.Write CBool(-1)
                    > Response.Write CBool(0)
                    > Response.Write CBool(1)
                    > Response.Write CBool(2)
                    >
                    > %>
                    > Here is the result I get from this:
                    > TrueFalseTrueTr ue
                    > So you see that CBool(2) resulted in True. In fact, the only one that
                    > resulted in False was 0.
                    >
                    > In fact, try this:
                    > <%
                    > if (1+3) then
                    > Response.Write "<br>true"
                    > else
                    > Response.Write "<br>false"
                    > end if
                    >
                    > s="abcd"
                    > Response.Write "<BR>" & instr(s,"c")
                    > if instr(s,"c") then
                    > Response.Write "<BR>c is in abcd"
                    > else
                    > Response.Write "<BR>c is not in abcd"
                    > end if
                    > %>
                    >
                    >
                    > This is the real reason both Yes/No values from Access and bit values
                    > from SQL Server work well in vbscript/vb.
                    > I'm still not clear about why your boolean values from MySQL aren't
                    > working the same way.[/color]

                    Actually the reason it works is that if you check the field type property it
                    is set to adBoolean (11) that is boolean.
                    Since the value property is a variant it will contain either -1 for True or
                    0 for False.

                    I suspect the MySQL isn't using this adBoolean (probably adUnsignedTinyI nt
                    or some such) and therefore the value comes through as 1


                    [color=blue]
                    >
                    > Bob Barrows
                    >
                    > *I realize I mistakenly said the reverse of this in my earlier message -
                    > my apologies.
                    > --
                    > Microsoft MVP -- ASP/ASP.NET
                    > Please reply to the newsgroup. The email account listed in my From
                    > header is my spam trap, so I don't check it very often. You will get a
                    > quicker response by posting to the newsgroup.
                    >
                    >[/color]


                    Comment

                    • Bob Barrows [MVP]

                      #25
                      Re: (true = 1) returns false?

                      Anthony Jones wrote:[color=blue][color=green]
                      >> This is the real reason both Yes/No values from Access and bit values
                      >> from SQL Server work well in vbscript/vb.
                      >> I'm still not clear about why your boolean values from MySQL aren't
                      >> working the same way.[/color]
                      >
                      > Actually the reason it works is that if you check the field type
                      > property it is set to adBoolean (11) that is boolean.
                      > Since the value property is a variant it will contain either -1 for
                      > True or 0 for False.
                      >
                      > I suspect the MySQL isn't using this adBoolean (probably
                      > adUnsignedTinyI nt or some such) and therefore the value comes through
                      > as 1
                      >[/color]
                      Yes, you're probably correct.
                      --
                      Microsoft MVP -- ASP/ASP.NET
                      Please reply to the newsgroup. The email account listed in my From
                      header is my spam trap, so I don't check it very often. You will get a
                      quicker response by posting to the newsgroup.


                      Comment

                      • Jason

                        #26
                        Re: (true = 1) returns false?

                        "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                        news:u9Jaz4aiGH A.1508@TK2MSFTN GP04.phx.gbl...[color=blue]
                        >
                        > This is the real reason both Yes/No values from Access and bit values
                        > from SQL Server work well in vbscript/vb.
                        > I'm still not clear about why your boolean values from MySQL aren't
                        > working the same way.
                        >
                        > Bob Barrows
                        >[/color]
                        I'm not clear why either. :)

                        --jason


                        Comment

                        • Jason

                          #27
                          Re: (true = 1) returns false? -- THE ANSWER

                          "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                          news:ebBpHBjiGH A.3496@TK2MSFTN GP02.phx.gbl...[color=blue]
                          > Anthony Jones wrote:[color=green][color=darkred]
                          >>> This is the real reason both Yes/No values from Access and bit values
                          >>> from SQL Server work well in vbscript/vb.
                          >>> I'm still not clear about why your boolean values from MySQL aren't
                          >>> working the same way.[/color]
                          >>
                          >> Actually the reason it works is that if you check the field type
                          >> property it is set to adBoolean (11) that is boolean.
                          >> Since the value property is a variant it will contain either -1 for
                          >> True or 0 for False.
                          >>
                          >> I suspect the MySQL isn't using this adBoolean (probably
                          >> adUnsignedTinyI nt or some such) and therefore the value comes through
                          >> as 1
                          >>[/color]
                          > Yes, you're probably correct.
                          > --
                          > Microsoft MVP -- ASP/ASP.NET
                          > Please reply to the newsgroup. The email account listed in my From
                          > header is my spam trap, so I don't check it very often. You will get a
                          > quicker response by posting to the newsgroup.
                          >[/color]
                          Ok, I figured out why we're having this problem. And it's kind of my bad,
                          kind of. :P I assumed it would work the same way it does in C++, but it
                          doesn't.

                          My if statements look like this:

                          <%
                          if rsobj("column") = true then
                          %>

                          and that fails, but if I change them to this:

                          <%
                          if rsobj("colum") then
                          %>

                          then it works.

                          It appears that true is just an alias for -1. So ASP (using vbscript) as a
                          language defines true as anything except false, and defines false as zero,
                          but the keyword true is only defined as -1.

                          I can't say I am pleased with this, but I am pleased with knowing why.

                          --jason


                          Comment

                          • Jason

                            #28
                            Re: (true = 1) returns false?

                            "Jason" <bigwheels16 hotmail> wrote in message
                            news:DtudnU-1nsykihrZnZ2dnU VZ_s6dnZ2d@comc ast.com...[color=blue]
                            > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                            > news:u9Jaz4aiGH A.1508@TK2MSFTN GP04.phx.gbl...[color=green]
                            >>
                            >> This is the real reason both Yes/No values from Access and bit values
                            >> from SQL Server work well in vbscript/vb.
                            >> I'm still not clear about why your boolean values from MySQL aren't
                            >> working the same way.
                            >>
                            >> Bob Barrows
                            >>[/color]
                            > I'm not clear why either. :)
                            >
                            > --jason[/color]
                            I posted this just before I discovered why.

                            --jason


                            Comment

                            • Anthony Jones

                              #29
                              Re: (true = 1) returns false? -- THE ANSWER


                              "Jason" <bigwheels16 hotmail> wrote in message
                              news:z4mdnQX7S9 gugBrZnZ2dnUVZ_ t2dnZ2d@comcast .com...[color=blue]
                              > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
                              > news:ebBpHBjiGH A.3496@TK2MSFTN GP02.phx.gbl...[color=green]
                              > > Anthony Jones wrote:[color=darkred]
                              > >>> This is the real reason both Yes/No values from Access and bit values
                              > >>> from SQL Server work well in vbscript/vb.
                              > >>> I'm still not clear about why your boolean values from MySQL aren't
                              > >>> working the same way.
                              > >>
                              > >> Actually the reason it works is that if you check the field type
                              > >> property it is set to adBoolean (11) that is boolean.
                              > >> Since the value property is a variant it will contain either -1 for
                              > >> True or 0 for False.
                              > >>
                              > >> I suspect the MySQL isn't using this adBoolean (probably
                              > >> adUnsignedTinyI nt or some such) and therefore the value comes through
                              > >> as 1
                              > >>[/color]
                              > > Yes, you're probably correct.
                              > > --
                              > > Microsoft MVP -- ASP/ASP.NET
                              > > Please reply to the newsgroup. The email account listed in my From
                              > > header is my spam trap, so I don't check it very often. You will get a
                              > > quicker response by posting to the newsgroup.
                              > >[/color]
                              > Ok, I figured out why we're having this problem. And it's kind of my bad,
                              > kind of. :P I assumed it would work the same way it does in C++, but it
                              > doesn't.
                              >
                              > My if statements look like this:
                              >
                              > <%
                              > if rsobj("column") = true then
                              > %>
                              >
                              > and that fails, but if I change them to this:
                              >
                              > <%
                              > if rsobj("colum") then
                              > %>
                              >
                              > then it works.
                              >
                              > It appears that true is just an alias for -1. So ASP (using vbscript) as[/color]
                              a[color=blue]
                              > language defines true as anything except false, and defines false as zero,
                              > but the keyword true is only defined as -1.
                              >
                              > I can't say I am pleased with this, but I am pleased with knowing why.
                              >[/color]


                              Take this C++ :-

                              if (5 == true)
                              // 5 is equal to true this doesn't happen
                              else
                              // 5 is not equal to true this happens


                              However things are different if you do this:-

                              if (1 == true)
                              // 1 is equal to true this does happen
                              else
                              // 1 is not equal to true this doesn't happen

                              or this:-

                              if (5)
                              // This always happens
                              else
                              // This never happens


                              In C/C++ (as is the same with VB/Script) when a boolean type and a numeric
                              type are either side of an operand it is the boolean which is coerced to a
                              numeric. However the C/C++ true is an 'alias' for 1 whereas in
                              VB/Script/COM a true is -1. The reason -1 was chosen is that VB does not
                              differentiate between bitwise and logical operators (e.g. & or && in C)
                              it only has bitwise operators (and, or, not).

                              It seems you have two problems.

                              1) using 'if x = true then' forces the true to be coerced to a numeric and
                              then a comparison is made and then a branch is made accordingly. Whereas
                              'if x Then' simply branches to 'then' on non-zero and 'else' on zero.

                              2) rsobj("column") isn't a boolean type but some kind of numeric type
                              (although I have found some interface declare a COM interface having a
                              boolean parameter or member but actually use 1 instead of -1 but that is
                              poor implementation) .

                              Frankly stop doing this x = true and be aware that all apparently logical
                              operators in VB are in fact bitwise

                              [color=blue]
                              > --jason
                              >
                              >[/color]


                              Comment

                              • Bob Barrows [MVP]

                                #30
                                Re: (true = 1) returns false? -- THE ANSWER

                                Anthony Jones wrote:[color=blue]
                                > 2) rsobj("column") isn't a boolean type but some kind of numeric type
                                > (although I have found some interface declare a COM interface having a
                                > boolean parameter or member but actually use 1 instead of -1 but that
                                > is poor implementation) .
                                >
                                > Frankly stop doing this x = true and be aware that all apparently
                                > logical operators in VB are in fact bitwise
                                >
                                >[/color]
                                An alternative would be to coerce the MySQL boolean trues to -1, perhaps
                                using a view with a calculated column.

                                --
                                Microsoft MVP - ASP/ASP.NET
                                Please reply to the newsgroup. This email account is my spam trap so I
                                don't check it very often. If you must reply off-line, then remove the
                                "NO SPAM"


                                Comment

                                Working...