(true = 1) returns false?

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

    (true = 1) returns false?

    I am fairly new to ASP--I have been using it about 2 months. I did these
    tests (below), and it doesn't make sense to me. False is equal to 0, and
    that's fine. True should be equal to 1, but it's not. Actually, True
    should be equal to anything but False, null, and 0. Is there a workaround
    for this? Or do I need to change all my comparisons to = 1 instead of =
    true?

    response.write True = 1 'prints False
    response.write True = 0 'prints False
    response.write False = 1 'prints False
    response.write False = 0 'prints True

    Just fyi, I am trying to convert our database from Access to MySQL. Access
    stores boolean as true/false, and MySQL stores booleans as 1 and 0, which is
    why I have this problem.

    Thanks in advance for your responses.

    --Jason
    Webmaster
    Substitute Teaching Institute,
    Utah State University


  • Bob Barrows [MVP]

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

    Jason wrote:[color=blue]
    > I am fairly new to ASP--I have been using it about 2 months. I did
    > these tests (below), and it doesn't make sense to me. False is equal
    > to 0, and that's fine. True should be equal to 1,[/color]

    Why do you think that?
    See


    [color=blue]
    > but it's not. Actually, True should be equal to anything but False, null,
    > and 0.[/color]

    No, that's not the way it works. In vbscript, if an expression evluates
    to -1 then the statement is true. Otherwise, it is false
    [color=blue]
    > Is there a workaround for this? Or do I need to change all my
    > comparisons to = 1 instead of = true?[/color]

    Huh? Why would you need to do that? Give me an example of something that is
    failing you because you are saying "= true" instead of "= -1"
    [color=blue]
    >
    > response.write True = 1 'prints False
    > response.write True = 0 'prints False
    > response.write False = 1 'prints False
    > response.write False = 0 'prints True
    >[/color]

    Try:
    Response.Write CBool(-1)
    Response.Write CBool(0)
    Response.Write CBool(1)
    Response.Write CBool(null)
    [color=blue]
    > Just fyi, I am trying to convert our database from Access to MySQL.[/color]

    You're familiar with Access? True is not even equal to 1 in Access!

    Where did you get the idea that it was equal to 1 in Access?
    [color=blue]
    > Access stores boolean as true/false,[/color]

    In actuality, Access (Jet) stores 0 for false/off/no and -1 for true/on/yes.
    This is easy to find out on your own. Create a table with a single Yes/No
    field, put some data inot it, then run this sql statement:

    select boolean_column, cint(boolean_co lumn) as int_equivalent
    from yourtable
    [color=blue]
    > and MySQL stores booleans as 1
    > and 0, which is why I have this problem.
    >[/color]

    I don't work with MySQL but I don't think MySQL has a boolean datatype; at
    least it doesn't if it's similar to SQL Server, which has a bit datatype,
    not boolean. What's the difference, you ask? A boolean can have two values:
    true or false. A bit can have 3 possible values: true, false or null.

    The OLE DB provider commonly handles conversions between vbscript and sql.
    So if you run a query against Access, you treat the data returned as if it
    was a native vbscript boolean subtype. The same thing will occur if you go
    against mysql or sql server: the bit datatype will be correctly translated
    to the vbscript boolean value.


    --
    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

    • Jason

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


      "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
      news:uqeyX5DhGH A.3924@TK2MSFTN GP03.phx.gbl...[color=blue]
      > Jason wrote:[color=green]
      >> I am fairly new to ASP--I have been using it about 2 months. I did
      >> these tests (below), and it doesn't make sense to me. False is equal
      >> to 0, and that's fine. True should be equal to 1,
      >> but it's not. Actually, True should be equal to anything but False, null,
      >> and 0.[/color]
      >
      > No, that's not the way it works. In vbscript, if an expression evluates
      > to -1 then the statement is true. Otherwise, it is false
      >[/color]

      I should have worded my question differently. That's what I was asking
      though, if VBscript followed the traditional definitions for true and false.
      [color=blue][color=green]
      >> Is there a workaround for this? Or do I need to change all my
      >> comparisons to = 1 instead of = true?[/color]
      >
      > Huh? Why would you need to do that? Give me an example of something that
      > is failing you because you are saying "= true" instead of "= -1"[/color]

      MySQL stores true as 1, not -1.
      [color=blue]
      >[color=green]
      >> Just fyi, I am trying to convert our database from Access to MySQL.[/color]
      >
      > You're familiar with Access? True is not even equal to 1 in Access![/color]

      Not really that familiar with Access, no.
      [color=blue]
      >
      > Where did you get the idea that it was equal to 1 in Access?[/color]

      I didn't say that, but it's irrelevant now.
      [color=blue]
      > I don't work with MySQL but I don't think MySQL has a boolean datatype; at
      > least it doesn't if it's similar to SQL Server, which has a bit datatype,
      > not boolean. What's the difference, you ask? A boolean can have two
      > values: true or false. A bit can have 3 possible values: true, false or
      > null.[/color]

      MySQL stores booleans as an integers (unsigned I think), one byte big. 0 is
      false, 1 is true. I haven't tested this, but I think MySQL treats any value
      other than 0 as true. However, when you store a value as true, it's stored
      as 1.
      [color=blue]
      >
      > The OLE DB provider commonly handles conversions between vbscript and sql.
      > So if you run a query against Access, you treat the data returned as if it
      > was a native vbscript boolean subtype. The same thing will occur if you go
      > against mysql or sql server: the bit datatype will be correctly translated
      > to the vbscript boolean value.
      >[/color]

      That's the problem then, it's not being translated correctly from MySQL.
      I'm not sure if I am using OLE DB or not.
      This is the code I use to connect:

      Dim sConnection, mysqlConn
      sConnection = "DRIVER={My SQL ODBC 3.51 Driver}; SERVER=localhos t;
      DATABASE=myDB; UID=user;PASSWO RD=pass; OPTION=3"
      Set mysqlConn = Server.CreateOb ject("ADODB.Con nection")
      mysqlConn.Open( sConnection)

      Is that using the OLE DB provider?


      Comment

      • Patrice

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

        The relevant part would be rather how you pass those data to MySQL rather
        than the connection string...

        You way want to use parametized queries instead of stuffing text into an SQL
        statement (if this is the problem). It will take care of this as well as
        from possible problem with date formats and decimal values whose text is
        country dependant...

        A MySQL forum might be a better place (for example if this something
        specific to the dat type you used for your column, is this defined as a
        boolean or as an integer ?)...

        --
        Patrice

        "Jason" <bigwheels16 hotmail> a écrit dans le message de news:
        KOSdnTCu6MYaQOH ZnZ2dnUVZ_uWdnZ 2d@comcast.com...[color=blue]
        >
        > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
        > news:uqeyX5DhGH A.3924@TK2MSFTN GP03.phx.gbl...[color=green]
        >> Jason wrote:[color=darkred]
        >>> I am fairly new to ASP--I have been using it about 2 months. I did
        >>> these tests (below), and it doesn't make sense to me. False is equal
        >>> to 0, and that's fine. True should be equal to 1,
        >>> but it's not. Actually, True should be equal to anything but False,
        >>> null, and 0.[/color]
        >>
        >> No, that's not the way it works. In vbscript, if an expression evluates
        >> to -1 then the statement is true. Otherwise, it is false
        >>[/color]
        >
        > I should have worded my question differently. That's what I was asking
        > though, if VBscript followed the traditional definitions for true and
        > false.
        >[color=green][color=darkred]
        >>> Is there a workaround for this? Or do I need to change all my
        >>> comparisons to = 1 instead of = true?[/color]
        >>
        >> Huh? Why would you need to do that? Give me an example of something that
        >> is failing you because you are saying "= true" instead of "= -1"[/color]
        >
        > MySQL stores true as 1, not -1.
        >[color=green]
        >>[color=darkred]
        >>> Just fyi, I am trying to convert our database from Access to MySQL.[/color]
        >>
        >> You're familiar with Access? True is not even equal to 1 in Access![/color]
        >
        > Not really that familiar with Access, no.
        >[color=green]
        >>
        >> Where did you get the idea that it was equal to 1 in Access?[/color]
        >
        > I didn't say that, but it's irrelevant now.
        >[color=green]
        >> I don't work with MySQL but I don't think MySQL has a boolean datatype;
        >> at least it doesn't if it's similar to SQL Server, which has a bit
        >> datatype, not boolean. What's the difference, you ask? A boolean can have
        >> two values: true or false. A bit can have 3 possible values: true, false
        >> or null.[/color]
        >
        > MySQL stores booleans as an integers (unsigned I think), one byte big. 0
        > is false, 1 is true. I haven't tested this, but I think MySQL treats any
        > value other than 0 as true. However, when you store a value as true, it's
        > stored as 1.
        >[color=green]
        >>
        >> The OLE DB provider commonly handles conversions between vbscript and
        >> sql. So if you run a query against Access, you treat the data returned as
        >> if it was a native vbscript boolean subtype. The same thing will occur if
        >> you go against mysql or sql server: the bit datatype will be correctly
        >> translated to the vbscript boolean value.
        >>[/color]
        >
        > That's the problem then, it's not being translated correctly from MySQL.
        > I'm not sure if I am using OLE DB or not.
        > This is the code I use to connect:
        >
        > Dim sConnection, mysqlConn
        > sConnection = "DRIVER={My SQL ODBC 3.51 Driver}; SERVER=localhos t;
        > DATABASE=myDB; UID=user;PASSWO RD=pass; OPTION=3"
        > Set mysqlConn = Server.CreateOb ject("ADODB.Con nection")
        > mysqlConn.Open( sConnection)
        >
        > Is that using the OLE DB provider?
        >[/color]


        Comment

        • Bob Barrows [MVP]

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

          Jason wrote:[color=blue]
          > "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
          > news:uqeyX5DhGH A.3924@TK2MSFTN GP03.phx.gbl...[color=green]
          >> Jason wrote:[color=darkred]
          >>> I am fairly new to ASP--I have been using it about 2 months. I did
          >>> these tests (below), and it doesn't make sense to me. False is
          >>> equal to 0, and that's fine. True should be equal to 1,
          >>> but it's not. Actually, True should be equal to anything but False,
          >>> null, and 0.[/color]
          >>
          >> No, that's not the way it works. In vbscript, if an expression
          >> evluates to -1 then the statement is true. Otherwise, it is false
          >>[/color]
          >
          > I should have worded my question differently. That's what I was
          > asking though, if VBscript followed the traditional definitions for
          > true and false.[/color]

          I guess I'm having trouble with the word "traditiona l". But I think the
          question is answered.
          [color=blue]
          >[color=green][color=darkred]
          >>> Is there a workaround for this? Or do I need to change all my
          >>> comparisons to = 1 instead of = true?[/color]
          >>
          >> Huh? Why would you need to do that? Give me an example of something
          >> that is failing you because you are saying "= true" instead of "= -1"[/color]
          >
          > MySQL stores true as 1, not -1.[/color]

          I'm not sure this is relevant, but given that I've never used MySQL, it may
          be.

          Could you show me an example where this causes a problem for you? Maybe we
          can suggest something if the MySQL ODBC driver is not doing what it's
          supposed to do.
          [color=blue]
          > That's the problem then, it's not being translated correctly from
          > MySQL. I'm not sure if I am using OLE DB or not.
          > This is the code I use to connect:
          >
          > Dim sConnection, mysqlConn
          > sConnection = "DRIVER={My SQL ODBC 3.51 Driver}; SERVER=localhos t;
          > DATABASE=myDB; UID=user;PASSWO RD=pass; OPTION=3"
          > Set mysqlConn = Server.CreateOb ject("ADODB.Con nection")
          > mysqlConn.Open( sConnection)
          >
          > Is that using the OLE DB provider?[/color]

          With ADO, you are always using an OLE DB provider. In this case you are
          using the MSDASQL provider, which is the Provider for ODBC, i.e., it
          provides the interface between ODBC drivers and ADO.

          --
          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

          • Jason

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

            "Bob Barrows [MVP]" <reb01501@NOyah oo.SPAMcom> wrote in message
            news:eXyc$TKhGH A.5088@TK2MSFTN GP02.phx.gbl...[color=blue]
            > Jason wrote:
            >[color=green]
            >> MySQL stores true as 1, not -1.[/color][/color]

            Just an fyi, I did a test, and MySQL does not treat any value besides 0 as
            true, so sorry about that bad info.
            [color=blue]
            >
            > I'm not sure this is relevant, but given that I've never used MySQL, it
            > may be.
            >
            > Could you show me an example where this causes a problem for you? Maybe we
            > can suggest something if the MySQL ODBC driver is not doing what it's
            > supposed to do.[/color]

            Sure. Here's a test table I created.

            create table test (
            id int not null primary key,
            name char(30),
            isMale bool
            );

            Which generates this table:

            +--------+------------+------+-----+---------+-------+
            | Field | Type | Null | Key | Default | Extra |
            +--------+------------+------+-----+---------+-------+
            | id int(11) PRI 0
            | name char(30) YES NULL
            | isMale tinyint(1) YES NULL
            +--------+------------+------+-----+---------+-------+

            so you can see the bool is stored as a 1 byte int.

            Then I insert two rows:
            insert into test VALUES(1, 'Jack', true);
            insert into test VALUES(2, 'Jill', false);

            The resulting table rows are:
            +----+------+--------+
            | id | name | isMale |
            +----+------+--------+
            | 1 Jack 1
            | 2 Jill 0
            +----+------+--------+

            1 for true, 0 for false.

            This is some sample code to demonstrate the problem:
            '--------
            strquery = "SELECT * FROM test"
            set rsobj = objconn.execute (strquery)

            while NOT rsobj.eof

            if rsobj("isMale") = true then
            response.write rsobj("name") & "<br />"
            end if

            rsobj.MoveNext
            wend
            '---------

            Nothing prints. If I change the IF statement to ' if rsobj("isMale") =
            false then ' then it will print ' Jill '. Or if I change the value of
            isMale for Jack to -1, then it will also work as intended, but MySQL doesn't
            recognize -1 as true. I realize I may have to change my code, but I would
            like to avoid that if possible becuase it would take a lot of changes.

            It must store bools as signed ints, instead of unsigned ints, since it let
            me change it to -1, so sorry about that bad info before also.

            Thank you for your replies.

            --Jason
            [color=blue]
            >
            > With ADO, you are always using an OLE DB provider. In this case you are
            > using the MSDASQL provider, which is the Provider for ODBC, i.e., it
            > provides the interface between ODBC drivers and ADO.
            >
            > --
            > 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"
            >[/color]


            Comment

            • Jason

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

              "Patrice" <scribe@chez.co m> wrote in message
              news:%23PtVd8Ih GHA.3996@TK2MSF TNGP03.phx.gbl. ..[color=blue]
              > The relevant part would be rather how you pass those data to MySQL rather
              > than the connection string...
              >
              > You way want to use parametized queries instead of stuffing text into an
              > SQL statement (if this is the problem). It will take care of this as well
              > as from possible problem with date formats and decimal values whose text
              > is country dependant...
              >
              > A MySQL forum might be a better place (for example if this something
              > specific to the dat type you used for your column, is this defined as a
              > boolean or as an integer ?)...
              >
              > --
              > Patrice
              >[/color]

              To be honest, I am not real familiar with parametized queries. Would using
              parametized queries require a code change in every place that I query the db
              and get bool results back?

              Thanks for your reply.

              --Jason


              Comment

              • Patrice

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

                Yes, it would require changes...

                Let's take things the other way round. My first thought would be that MySQL
                doesn't really have boolean columns (I thought of this because you said that
                MySQL consider as true any non 0 value. If the column was really a boolean
                you could only have 3 possible values).

                If MySQL doesn't provide an explicit boolean datatype the db layer won't
                have any kind of translation... You could easily then transmit a wrong
                value.

                Don't assume anything about the value of boleans and use something like
                IIf(Condition,1 ,0)so that you explicity code the value used by MySQL in your
                SQL statements (of course you could use your own small function so that you
                can eventually change this one day). It will also require changes... Finally
                you could just transform -1 to 1 server side if possible (would require just
                a small server side change ?)

                --
                Patrice

                "Jason" <bigwheels16 hotmail> a écrit dans le message de news:
                _bGdnQo6IYPqe-DZnZ2dnUVZ_s-dnZ2d@comcast.c om...[color=blue]
                > "Patrice" <scribe@chez.co m> wrote in message
                > news:%23PtVd8Ih GHA.3996@TK2MSF TNGP03.phx.gbl. ..[color=green]
                >> The relevant part would be rather how you pass those data to MySQL rather
                >> than the connection string...
                >>
                >> You way want to use parametized queries instead of stuffing text into an
                >> SQL statement (if this is the problem). It will take care of this as well
                >> as from possible problem with date formats and decimal values whose text
                >> is country dependant...
                >>
                >> A MySQL forum might be a better place (for example if this something
                >> specific to the dat type you used for your column, is this defined as a
                >> boolean or as an integer ?)...
                >>
                >> --
                >> Patrice
                >>[/color]
                >
                > To be honest, I am not real familiar with parametized queries. Would
                > using parametized queries require a code change in every place that I
                > query the db and get bool results back?
                >
                > Thanks for your reply.
                >
                > --Jason
                >[/color]


                Comment

                • John Fullmer

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

                  Good example of this is the .checked value of a checkbox. it will
                  return a -1 if checked (vbscript). Easy to work around with a
                  CBool(obj.check ed) or cint(obj.checke d) * -1 depending on the desired
                  output.

                  ~ John Fullmer


                  Bob Barrows [MVP] wrote:[color=blue]
                  > Jason wrote:[color=green]
                  > > I am fairly new to ASP--I have been using it about 2 months. I did
                  > > these tests (below), and it doesn't make sense to me. False is equal
                  > > to 0, and that's fine. True should be equal to 1,[/color]
                  >
                  > Why do you think that?
                  > See
                  > http://msdn.microsoft.com/library/en...500872d64f.asp
                  >
                  >[color=green]
                  > > but it's not. Actually, True should be equal to anything but False, null,
                  > > and 0.[/color]
                  >
                  > No, that's not the way it works. In vbscript, if an expression evluates
                  > to -1 then the statement is true. Otherwise, it is false
                  >[color=green]
                  > > Is there a workaround for this? Or do I need to change all my
                  > > comparisons to = 1 instead of = true?[/color]
                  >
                  > Huh? Why would you need to do that? Give me an example of something that is
                  > failing you because you are saying "= true" instead of "= -1"
                  >[color=green]
                  > >
                  > > response.write True = 1 'prints False
                  > > response.write True = 0 'prints False
                  > > response.write False = 1 'prints False
                  > > response.write False = 0 'prints True
                  > >[/color]
                  >
                  > Try:
                  > Response.Write CBool(-1)
                  > Response.Write CBool(0)
                  > Response.Write CBool(1)
                  > Response.Write CBool(null)
                  >[color=green]
                  > > Just fyi, I am trying to convert our database from Access to MySQL.[/color]
                  >
                  > You're familiar with Access? True is not even equal to 1 in Access!
                  >
                  > Where did you get the idea that it was equal to 1 in Access?
                  >[color=green]
                  > > Access stores boolean as true/false,[/color]
                  >
                  > In actuality, Access (Jet) stores 0 for false/off/no and -1 for true/on/yes.
                  > This is easy to find out on your own. Create a table with a single Yes/No
                  > field, put some data inot it, then run this sql statement:
                  >
                  > select boolean_column, cint(boolean_co lumn) as int_equivalent
                  > from yourtable
                  >[color=green]
                  > > and MySQL stores booleans as 1
                  > > and 0, which is why I have this problem.
                  > >[/color]
                  >
                  > I don't work with MySQL but I don't think MySQL has a boolean datatype; at
                  > least it doesn't if it's similar to SQL Server, which has a bit datatype,
                  > not boolean. What's the difference, you ask? A boolean can have two values:
                  > true or false. A bit can have 3 possible values: true, false or null.
                  >
                  > The OLE DB provider commonly handles conversions between vbscript and sql.
                  > So if you run a query against Access, you treat the data returned as if it
                  > was a native vbscript boolean subtype. The same thing will occur if you go
                  > against mysql or sql server: the bit datatype will be correctly translated
                  > to the vbscript boolean value.
                  >
                  >
                  > --
                  > 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"[/color]

                  Comment

                  • Jason

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

                    You're right, MySQL doesn't really have boolean data types. They are just
                    ints.

                    I could change all the 1's to -1's in the database, but then queries like
                    "SELECT * FROM table WHERE isOpen = true" would fail. MySQL only sees 1 as
                    true, 0 as false, and anything else is neither.

                    I am not sure what you mean by server side--the problem happens before the
                    client ever sees any html. The root of the problem is the mysql definition
                    of true vs the vbscript definition of true, where mysql defines trues as 1,
                    and vbscript defines true as -1. So I can either change the values in the
                    database, or I can change my code, and I don't want to change the database
                    for the reason stated above. So basically, I am left with changing code,
                    and that wouldn't be a quick change--there are lots of places I would have
                    to change, but I don't see another option. I think the best option would be
                    to use the CBool() function, so that is what I am going to do.

                    thanks for your replies

                    --Jason

                    "Patrice" <scribe@chez.co m> wrote in message
                    news:%239EzBIVh GHA.2456@TK2MSF TNGP04.phx.gbl. ..[color=blue]
                    > Yes, it would require changes...
                    >
                    > Let's take things the other way round. My first thought would be that
                    > MySQL doesn't really have boolean columns (I thought of this because you
                    > said that MySQL consider as true any non 0 value. If the column was really
                    > a boolean you could only have 3 possible values).
                    >
                    > If MySQL doesn't provide an explicit boolean datatype the db layer won't
                    > have any kind of translation... You could easily then transmit a wrong
                    > value.
                    >
                    > Don't assume anything about the value of boleans and use something like
                    > IIf(Condition,1 ,0)so that you explicity code the value used by MySQL in
                    > your SQL statements (of course you could use your own small function so
                    > that you can eventually change this one day). It will also require
                    > changes... Finally you could just transform -1 to 1 server side if
                    > possible (would require just a small server side change ?)
                    >
                    > --
                    > Patrice
                    >
                    > "Jason" <bigwheels16 hotmail> a écrit dans le message de news:
                    > _bGdnQo6IYPqe-DZnZ2dnUVZ_s-dnZ2d@comcast.c om...[color=green]
                    >> "Patrice" <scribe@chez.co m> wrote in message
                    >> news:%23PtVd8Ih GHA.3996@TK2MSF TNGP03.phx.gbl. ..[color=darkred]
                    >>> The relevant part would be rather how you pass those data to MySQL
                    >>> rather than the connection string...
                    >>>
                    >>> You way want to use parametized queries instead of stuffing text into an
                    >>> SQL statement (if this is the problem). It will take care of this as
                    >>> well as from possible problem with date formats and decimal values whose
                    >>> text is country dependant...
                    >>>
                    >>> A MySQL forum might be a better place (for example if this something
                    >>> specific to the dat type you used for your column, is this defined as a
                    >>> boolean or as an integer ?)...
                    >>>
                    >>> --
                    >>> Patrice
                    >>>[/color]
                    >>
                    >> To be honest, I am not real familiar with parametized queries. Would
                    >> using parametized queries require a code change in every place that I
                    >> query the db and get bool results back?
                    >>
                    >> Thanks for your reply.
                    >>
                    >> --Jason
                    >>[/color]
                    >
                    >[/color]


                    Comment

                    • Jason

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

                      Yeah, and I don't really see a better option than using CBool(). It won't
                      be quick but at least it will work.

                      --Jason

                      "John Fullmer" <jkf35@hotmail. com> wrote in message
                      news:1149176515 .871969.307760@ f6g2000cwb.goog legroups.com...[color=blue]
                      > Good example of this is the .checked value of a checkbox. it will
                      > return a -1 if checked (vbscript). Easy to work around with a
                      > CBool(obj.check ed) or cint(obj.checke d) * -1 depending on the desired
                      > output.
                      >
                      > ~ John Fullmer
                      >
                      >
                      > Bob Barrows [MVP] wrote:[color=green]
                      >> Jason wrote:[color=darkred]
                      >> > I am fairly new to ASP--I have been using it about 2 months. I did
                      >> > these tests (below), and it doesn't make sense to me. False is equal
                      >> > to 0, and that's fine. True should be equal to 1,[/color]
                      >>
                      >> Why do you think that?
                      >> See
                      >> http://msdn.microsoft.com/library/en...500872d64f.asp
                      >>
                      >>[color=darkred]
                      >> > but it's not. Actually, True should be equal to anything but False,
                      >> > null,
                      >> > and 0.[/color]
                      >>
                      >> No, that's not the way it works. In vbscript, if an expression evluates
                      >> to -1 then the statement is true. Otherwise, it is false
                      >>[color=darkred]
                      >> > Is there a workaround for this? Or do I need to change all my
                      >> > comparisons to = 1 instead of = true?[/color]
                      >>
                      >> Huh? Why would you need to do that? Give me an example of something that
                      >> is
                      >> failing you because you are saying "= true" instead of "= -1"
                      >>[color=darkred]
                      >> >
                      >> > response.write True = 1 'prints False
                      >> > response.write True = 0 'prints False
                      >> > response.write False = 1 'prints False
                      >> > response.write False = 0 'prints True
                      >> >[/color]
                      >>
                      >> Try:
                      >> Response.Write CBool(-1)
                      >> Response.Write CBool(0)
                      >> Response.Write CBool(1)
                      >> Response.Write CBool(null)
                      >>[color=darkred]
                      >> > Just fyi, I am trying to convert our database from Access to MySQL.[/color]
                      >>
                      >> You're familiar with Access? True is not even equal to 1 in Access!
                      >>
                      >> Where did you get the idea that it was equal to 1 in Access?
                      >>[color=darkred]
                      >> > Access stores boolean as true/false,[/color]
                      >>
                      >> In actuality, Access (Jet) stores 0 for false/off/no and -1 for
                      >> true/on/yes.
                      >> This is easy to find out on your own. Create a table with a single Yes/No
                      >> field, put some data inot it, then run this sql statement:
                      >>
                      >> select boolean_column, cint(boolean_co lumn) as int_equivalent
                      >> from yourtable
                      >>[color=darkred]
                      >> > and MySQL stores booleans as 1
                      >> > and 0, which is why I have this problem.
                      >> >[/color]
                      >>
                      >> I don't work with MySQL but I don't think MySQL has a boolean datatype;
                      >> at
                      >> least it doesn't if it's similar to SQL Server, which has a bit datatype,
                      >> not boolean. What's the difference, you ask? A boolean can have two
                      >> values:
                      >> true or false. A bit can have 3 possible values: true, false or null.
                      >>
                      >> The OLE DB provider commonly handles conversions between vbscript and
                      >> sql.
                      >> So if you run a query against Access, you treat the data returned as if
                      >> it
                      >> was a native vbscript boolean subtype. The same thing will occur if you
                      >> go
                      >> against mysql or sql server: the bit datatype will be correctly
                      >> translated
                      >> to the vbscript boolean value.
                      >>
                      >>
                      >> --
                      >> 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"[/color]
                      >[/color]


                      Comment

                      • roger

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

                        "Jason" <bigwheels16 hotmail> wrote in message
                        news:t9Sdndt2Ov dPfuDZnZ2dnUVZ_ vudnZ2d@comcast .com...
                        [color=blue]
                        > while NOT rsobj.eof
                        >
                        > if rsobj("isMale") = true then
                        > response.write rsobj("name") & "<br />"
                        > end if
                        >
                        > rsobj.MoveNext
                        > wend[/color]


                        How about...

                        if rsobj("isMale") then
                        response.write rsobj("name") & "<br />"
                        end if

                        Does that do what you want?


                        --
                        roger


                        Comment

                        • Jason

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

                          "roger" <mothland@btope nworld.com> wrote in message
                          news:%23VN32rhh GHA.3424@TK2MSF TNGP05.phx.gbl. ..[color=blue]
                          > "Jason" <bigwheels16 hotmail> wrote in message
                          > news:t9Sdndt2Ov dPfuDZnZ2dnUVZ_ vudnZ2d@comcast .com...
                          >
                          >
                          > How about...
                          >
                          > if rsobj("isMale") then
                          > response.write rsobj("name") & "<br />"
                          > end if
                          >
                          > Does that do what you want?
                          >
                          >[/color]

                          Well, if that worked, then yes :) but that doesn't work, which is the
                          problem.


                          Comment

                          • roger

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

                            "Jason" <bigwheels16 hotmail> wrote in message
                            news:yrOdnVm9ZY 0VER3ZnZ2dnUVZ_ sKdnZ2d@comcast .com...
                            [color=blue][color=green]
                            > > How about...
                            > >
                            > > if rsobj("isMale") then
                            > > response.write rsobj("name") & "<br />"
                            > > end if
                            > >
                            > > Does that do what you want?
                            > >
                            > >[/color]
                            >
                            > Well, if that worked, then yes :) but that doesn't work, which is the
                            > problem.[/color]

                            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?

                            --
                            roger


                            Comment

                            • Jason

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

                              "roger" <mothland@btope nworld.com> wrote in message
                              news:OPstqHohGH A.1272@TK2MSFTN GP03.phx.gbl...[color=blue]
                              >
                              >
                              > 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?
                              >
                              > --
                              > roger[/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.

                              --Jason


                              Comment

                              Working...