468,525 Members | 2,191 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,525 developers. It's quick & easy.

(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
May 30 '06 #1
30 2485
Jason wrote:
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,
Why do you think that?
See
http://msdn.microsoft.com/library/en...500872d64f.asp

but it's not. Actually, True should be equal to anything but False, null,
and 0.
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
Is there a workaround for this? Or do I need to change all my
comparisons to = 1 instead of = true?
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"

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

Try:
Response.Write CBool(-1)
Response.Write CBool(0)
Response.Write CBool(1)
Response.Write CBool(null)
Just fyi, I am trying to convert our database from Access to MySQL.
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?
Access stores boolean as true/false,
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_column) as int_equivalent
from yourtable
and MySQL stores booleans as 1
and 0, which is why I have this problem.


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"
May 30 '06 #2

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
Jason wrote:
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.
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


I should have worded my question differently. That's what I was asking
though, if VBscript followed the traditional definitions for true and false.
Is there a workaround for this? Or do I need to change all my
comparisons to = 1 instead of = true?


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"


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


Not really that familiar with Access, no.

Where did you get the idea that it was equal to 1 in Access?
I didn't say that, but it's irrelevant now.
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.
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.

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.


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={MySQL ODBC 3.51 Driver}; SERVER=localhost;
DATABASE=myDB; UID=user;PASSWORD=pass; OPTION=3"
Set mysqlConn = Server.CreateObject("ADODB.Connection")
mysqlConn.Open(sConnection)

Is that using the OLE DB provider?
May 31 '06 #3
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:
KO******************************@comcast.com...

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
Jason wrote:
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.


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


I should have worded my question differently. That's what I was asking
though, if VBscript followed the traditional definitions for true and
false.
Is there a workaround for this? Or do I need to change all my
comparisons to = 1 instead of = true?


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"


MySQL stores true as 1, not -1.
Just fyi, I am trying to convert our database from Access to MySQL.


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


Not really that familiar with Access, no.

Where did you get the idea that it was equal to 1 in Access?


I didn't say that, but it's irrelevant now.
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.


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.

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.


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={MySQL ODBC 3.51 Driver}; SERVER=localhost;
DATABASE=myDB; UID=user;PASSWORD=pass; OPTION=3"
Set mysqlConn = Server.CreateObject("ADODB.Connection")
mysqlConn.Open(sConnection)

Is that using the OLE DB provider?

May 31 '06 #4
Jason wrote:
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:uq**************@TK2MSFTNGP03.phx.gbl...
Jason wrote:
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.
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


I should have worded my question differently. That's what I was
asking though, if VBscript followed the traditional definitions for
true and false.


I guess I'm having trouble with the word "traditional". But I think the
question is answered.
Is there a workaround for this? Or do I need to change all my
comparisons to = 1 instead of = true?
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"


MySQL stores true as 1, not -1.


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.
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={MySQL ODBC 3.51 Driver}; SERVER=localhost;
DATABASE=myDB; UID=user;PASSWORD=pass; OPTION=3"
Set mysqlConn = Server.CreateObject("ADODB.Connection")
mysqlConn.Open(sConnection)

Is that using the OLE DB provider?


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"
May 31 '06 #5
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eX**************@TK2MSFTNGP02.phx.gbl...
Jason wrote:
MySQL stores true as 1, not -1.

Just an fyi, I did a test, and MySQL does not treat any value besides 0 as
true, so sorry about that bad info.

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

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"

May 31 '06 #6
"Patrice" <sc****@chez.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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


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
May 31 '06 #7
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:
_b******************************@comcast.com...
"Patrice" <sc****@chez.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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


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

Jun 1 '06 #8
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.checked) or cint(obj.checked) * -1 depending on the desired
output.

~ John Fullmer
Bob Barrows [MVP] wrote:
Jason wrote:
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,


Why do you think that?
See
http://msdn.microsoft.com/library/en...500872d64f.asp

but it's not. Actually, True should be equal to anything but False, null,
and 0.


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
Is there a workaround for this? Or do I need to change all my
comparisons to = 1 instead of = true?


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"

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


Try:
Response.Write CBool(-1)
Response.Write CBool(0)
Response.Write CBool(1)
Response.Write CBool(null)
Just fyi, I am trying to convert our database from Access to MySQL.


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?
Access stores boolean as true/false,


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_column) as int_equivalent
from yourtable
and MySQL stores booleans as 1
and 0, which is why I have this problem.


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"


Jun 1 '06 #9
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" <sc****@chez.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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:
_b******************************@comcast.com...
"Patrice" <sc****@chez.com> wrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
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


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


Jun 1 '06 #10
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" <jk***@hotmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
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.checked) or cint(obj.checked) * -1 depending on the desired
output.

~ John Fullmer
Bob Barrows [MVP] wrote:
Jason wrote:
> 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,


Why do you think that?
See
http://msdn.microsoft.com/library/en...500872d64f.asp

> but it's not. Actually, True should be equal to anything but False,
> null,
> and 0.


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
> Is there a workaround for this? Or do I need to change all my
> comparisons to = 1 instead of = true?


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"
>
> response.write True = 1 'prints False
> response.write True = 0 'prints False
> response.write False = 1 'prints False
> response.write False = 0 'prints True
>


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


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?
> Access stores boolean as true/false,


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_column) as int_equivalent
from yourtable
> and MySQL stores booleans as 1
> and 0, which is why I have this problem.
>


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"

Jun 1 '06 #11
"Jason" <bigwheels16 hotmail> wrote in message
news:t9******************************@comcast.com. ..
while NOT rsobj.eof

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

rsobj.MoveNext
wend

How about...

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

Does that do what you want?
--
roger
Jun 2 '06 #12
"roger" <mo******@btopenworld.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
"Jason" <bigwheels16 hotmail> wrote in message
news:t9******************************@comcast.com. ..
How about...

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

Does that do what you want?


Well, if that worked, then yes :) but that doesn't work, which is the
problem.
Jun 2 '06 #13
"Jason" <bigwheels16 hotmail> wrote in message
news:yr******************************@comcast.com. ..
How about...

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

Does that do what you want?


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


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
Jun 2 '06 #14
"roger" <mo******@btopenworld.com> wrote in message
news:OP**************@TK2MSFTNGP03.phx.gbl...


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


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
Jun 6 '06 #15
Jason wrote on 06 jun 2006 in microsoft.public.inetserver.asp.general:
"roger" <mo******@btopenworld.com> wrote in message


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?


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.


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)
Jun 6 '06 #16

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn********************@194.109.133.242...
works for you and not for me.


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

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.
Jun 6 '06 #17
Jason wrote on 06 jun 2006 in microsoft.public.inetserver.asp.general:
"Evertjan." <ex**************@interxnl.net> wrote in message
works for you and not for me.


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

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.


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)
Jun 6 '06 #18
>
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.

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.
Jun 6 '06 #19
Jason wrote on 06 jun 2006 in microsoft.public.inetserver.asp.general:
if you want to test for "true", "false" and "neither",
my above code remains necassary, IMHO.
I don't think you understand the problem.


True.
ASP defines 0 as false and
-1 as true, and everything else is neither.
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

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.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 6 '06 #20
Jason wrote:

I don't think you understand the problem. ASP defines 0 as false and
-1 as true, and everything else is neither.


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:
TrueFalseTrueTrue
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.
Jun 6 '06 #21

Bob Barrows [MVP] wrote:
Jason wrote:

I don't think you understand the problem. ASP defines 0 as false and
-1 as true, and everything else is neither.


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


Interestingly, this is exactly the same in MySQL:
(See BOOL,BOOLEAN subhead)
http://dev.mysql.com/doc/refman/5.0/...-overview.html

--
Mike Brind

Jun 6 '06 #22

"Jason" <bigwheels16 hotmail> wrote in message
news:3s******************************@comcast.com. ..
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.

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
Jun 7 '06 #23

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:u9**************@TK2MSFTNGP04.phx.gbl...
Jason wrote:
I don't think you understand the problem. ASP defines 0 as false and
-1 as true, and everything else is neither.


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:
TrueFalseTrueTrue
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.


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 adUnsignedTinyInt
or some such) and therefore the value comes through as 1

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.

Jun 7 '06 #24
Anthony Jones wrote:
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
adUnsignedTinyInt or some such) and therefore the value comes through
as 1

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.
Jun 7 '06 #25
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:u9**************@TK2MSFTNGP04.phx.gbl...

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'm not clear why either. :)

--jason
Jun 7 '06 #26
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eb**************@TK2MSFTNGP02.phx.gbl...
Anthony Jones wrote:
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
adUnsignedTinyInt or some such) and therefore the value comes through
as 1

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.

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
Jun 7 '06 #27
"Jason" <bigwheels16 hotmail> wrote in message
news:Dt******************************@comcast.com. ..
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:u9**************@TK2MSFTNGP04.phx.gbl...

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'm not clear why either. :)

--jason

I posted this just before I discovered why.

--jason
Jun 7 '06 #28

"Jason" <bigwheels16 hotmail> wrote in message
news:z4******************************@comcast.com. ..
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eb**************@TK2MSFTNGP02.phx.gbl...
Anthony Jones wrote:
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
adUnsignedTinyInt or some such) and therefore the value comes through
as 1
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.

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

--jason

Jun 8 '06 #29
Anthony Jones wrote:
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

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"
Jun 8 '06 #30
"Anthony Jones" <An*@yadayadayada.com> wrote in message
news:u3**************@TK2MSFTNGP04.phx.gbl...

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

Yeah, you are right. I assumed 'if b == true then...' and 'if b then...'
were identical statements, but they aren't. Your explanantion of how the
bool is casted as an int helps to make it clear as to why it happens because
I did not really know why.

--jason
Jun 8 '06 #31

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Daniel Klein | last post: by
3 posts views Thread by drs | last post: by
35 posts views Thread by Steven Bethard | last post: by
11 posts views Thread by Arpan | last post: by
14 posts views Thread by Walter Dnes (delete the 'z' to get my real address | last post: by
48 posts views Thread by Skybuck Flying | last post: by
59 posts views Thread by Pierre Quentel | last post: by
40 posts views Thread by nufuhsus | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.