Home All Groups Group Topic Archive Search About
Author
11 May 2005 4:22 PM
Chris Lieb
This has been bugging me for a while.  Why is VB like the only language that
treats the boolean value of True as the integer -1?  C/C++, C#, and Java, to
name a few, all treat it as the integer 1.  This gets to be annoying when you
are trying to set the value of a checkbox to 1.  When you set the value to
True, you get an error because -1 (boolean True) is not a valid property
value for the CheckBox.Value property.  In this case, the easiest way around
this is to wrap the boolean with Abs() to force it to output a 1 instead of a
-1.  Why did MS ever design VB this way?

--
Chris Lieb
UPS CACH, Hodgekins, IL
Tech Support Group - Systems/Apps

Author
11 May 2005 4:31 PM
Karl E. Peterson
Chris Lieb wrote:
> This has been bugging me for a while.  Why is VB like the only
> language that treats the boolean value of True as the integer -1?
> C/C++, C#, and Java, to name a few, all treat it as the integer 1.
> This gets to be annoying when you are trying to set the value of a
> checkbox to 1.  When you set the value to True, you get an error
> because -1 (boolean True) is not a valid property value for the
> CheckBox.Value property.  In this case, the easiest way around this
> is to wrap the boolean with Abs() to force it to output a 1 instead
> of a -1.  Why did MS ever design VB this way?

Simply put...  Every other language is wrong. <g>

Here's a more in-depth discussion/explanation:

  Microsoft Basic Logical Expression Evaluation
  http://vb.mvps.org/tips/truth.asp

Later...   Karl
--
Working Without a .NET?
http://classicvb.org/petition
Author
11 May 2005 8:27 PM
Jonathan Wood
Karl,

> Simply put...  Every other language is wrong. <g>
>
> Here's a more in-depth discussion/explanation:
>
>   Microsoft Basic Logical Expression Evaluation
>   http://vb.mvps.org/tips/truth.asp

I can't for the life of me understand why he continues to call VB's AND, OR,
XOR, etc. operators *logical*. They are bitwise, and that is why True should
be -1 in VB. If VB supported logical AND, OR, XOR, etc. operators, then it
wouldn't matter if True was -1 or 1, or 45 for that matter.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Author
11 May 2005 11:01 PM
Dan Barclay
Show quote
"Jonathan Wood" <jw***@softcircuits.com> wrote in message
news:%231kRlfmVFHA.628@tk2msftngp13.phx.gbl...
> Karl,
>
>> Simply put...  Every other language is wrong. <g>
>>
>> Here's a more in-depth discussion/explanation:
>>
>>   Microsoft Basic Logical Expression Evaluation
>>   http://vb.mvps.org/tips/truth.asp
>
> I can't for the life of me understand why he continues to call VB's AND,
> OR,
> XOR, etc. operators *logical*.

Could it be, perhaps, maybe, that this is how they are known generically?
Maybe it's possible that all the MS documentation for 30 years has refered
to them as logical operators?  Hmmm....

Tell ya what.  How about you get into ClassicVB, put yer cursor on one of
these critters (try "And" maybe), and see what the Help calls them.  You'll
get something like:

==============
Used to perform a logical conjunction on two expressions.

Syntax

result = expression1 And expression2

The And operator syntax has these parts:

Part Description
result Required; any numeric variable.
expression1 Required; any expression.
expression2 Required; any expression.
================

Heck, you might even want to look back to DOS or CP/M versions to see what
they say.

It's pretty much like I explained in the paper.

> They are bitwise, and that is why True should
> be -1 in VB. If VB supported logical AND, OR, XOR, etc. operators, then it
> wouldn't matter if True was -1 or 1, or 45 for that matter.

You need to read the paper again.  That's *exactly* what I said.

Did you even *read* it???!?!

They are *called* logical operators because, well, that's what they've been
called in Basic documentation!

If you want to use a definition from another language, maybe you should
consider using that definition in the context that language.

Later,
Dan
Author
11 May 2005 11:28 PM
Jonathan Wood
Dan,

> Tell ya what.  How about you get into ClassicVB, put yer cursor on one of
> these critters (try "And" maybe), and see what the Help calls them.
You'll
> get something like:

And this makes these operators other than bitwise?

> > They are bitwise, and that is why True should
> > be -1 in VB. If VB supported logical AND, OR, XOR, etc. operators, then
it
> > wouldn't matter if True was -1 or 1, or 45 for that matter.
>
> You need to read the paper again.  That's *exactly* what I said.

If you said that, then you agree that these operators are bitwise. So why
take exception to my comments? And why call them logical?

> If you want to use a definition from another language, maybe you should
> consider using that definition in the context that language.

I don't consider the term bitwise to be language-specific. Are you saying
otherwise?

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Author
12 May 2005 4:14 PM
Dan Barclay
Show quote
"Jonathan Wood" <jw***@softcircuits.com> wrote in message
news:Ot40wEoVFHA.3532@TK2MSFTNGP09.phx.gbl...
> Dan,
>
>> Tell ya what.  How about you get into ClassicVB, put yer cursor on one of
>> these critters (try "And" maybe), and see what the Help calls them.
> You'll
>> get something like:
>
> And this makes these operators other than bitwise?
>
>> > They are bitwise, and that is why True should
>> > be -1 in VB. If VB supported logical AND, OR, XOR, etc. operators, then
> it
>> > wouldn't matter if True was -1 or 1, or 45 for that matter.
>>
>> You need to read the paper again.  That's *exactly* what I said.
>
> If you said that, then you agree that these operators are bitwise. So why
> take exception to my comments? And why call them logical?
>
>> If you want to use a definition from another language, maybe you should
>> consider using that definition in the context that language.
>
> I don't consider the term bitwise to be language-specific. Are you saying
> otherwise?

I'm saying, in plain English, that Boolean operators in MS Basic product
documentation (and most discussion) are called Logical Operators.

Not only do the documentation sets call them logical, they are "logical" in
the sense that they are not arithmetic.

They are *also* bitwise, because that is how they are implemented.   They
are bitwise logical.  For example 01 AND 01 is 01.  If they were, for
arithmetic bitwise the result would be 10.

If you want to call them something else, that's fine.

Dan
Author
12 May 2005 12:18 AM
Larry Serflaten
"Jonathan Wood" <jw***@softcircuits.com> wrote

> I can't for the life of me understand why he continues to call VB's AND, OR,
> XOR, etc. operators *logical*. They are bitwise, and that is why True should
> be -1 in VB. If VB supported logical AND, OR, XOR, etc. operators, then it
> wouldn't matter if True was -1 or 1, or 45 for that matter.

I've always thought he's confused the issue, myself.  But, I approve of calling
them logical operators because they correspond to the named 'logic' gates found
in electronics.  Individual gates typically act on individual bits....

What I didn't like was the (abstracted) distinction between logical operations, and
boolean tests:

<quote>
First, understand that logical operations and tests are two different things.

For tests only (that is, the expression tested by IF and whatnot), a zero value
is judged to be false, any nonzero value is judged to be the truth (well, True).
</quote>

The sentence, "For tests only..." is clearly a misleading statement:

Debug.Print CBool(1)

Where is there any sort of 'test' in that???  Yet it results in a True or False result
depending on the numerical value used....

A more concise explaination:

VB's logical operations yield numerical results based on bitwise comparisons.  If the
result is not 0, then it is regarded as being True.  VB's value of True is an Integer
based on the result of the logical operation: X = Not False.

That is all there needs to be said on that topic.

LFS
Author
12 May 2005 12:30 AM
Jonathan Wood
Larry,

> I've always thought he's confused the issue, myself.  But, I approve of
calling
> them logical operators because they correspond to the named 'logic' gates
found
> in electronics.  Individual gates typically act on individual bits....

Okay, but as you state, they are acting on individual bits. That's what I've
always described as bitwise. To me, logical refers to a boolean state. What
names would you use to distinguish between the two?

> What I didn't like was the (abstracted) distinction between logical
operations, and
> boolean tests:

Heh, actually, I thought that part made sense because IF statements are
logical whereas AND, OR, etc. are bitwise. :-)

> The sentence, "For tests only..." is clearly a misleading statement:
>
> Debug.Print CBool(1)
>
> Where is there any sort of 'test' in that???  Yet it results in a True or
False result
> depending on the numerical value used....

Well, my description of "a boolean state" might be a bit more general here
than "for tests only."

> VB's logical operations yield numerical results based on bitwise
comparisons.  If the
> result is not 0, then it is regarded as being True.  VB's value of True is
an Integer
> based on the result of the logical operation: X = Not False.
>
> That is all there needs to be said on that topic.

I pretty much agree with that description. However, I know that people who
understand this still can get caught off guard by the behavior of the AND,
OR, etc. operators when applied to integer values. So my description might
go a bit more into detail about using those operators.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Author
12 May 2005 1:07 AM
Larry Serflaten
"Jonathan Wood" <jw***@softcircuits.com> wrote

> Okay, but as you state, they are acting on individual bits. That's what I've
> always described as bitwise. To me, logical refers to a boolean state. What
> names would you use to distinguish between the two?

Consider:  What is the logical outcome of this premis?

As you see the meaning of the term 'logical' is a bit too wide to try to tie it
to specific operations.  Why not just numerical, and boolean?


> Heh, actually, I thought that part made sense because IF statements are
> logical whereas AND, OR, etc. are bitwise. :-)

While you might appear to be logical, you would rarely ever appear to be bitwise!
Again, you can see 'logical' is a context based word, so finding another term to
narrow down the idea being communicated, would be beneficial.


> > That is all there needs to be said on that topic.
>
> I pretty much agree with that description. However, I know that people who
> understand this still can get caught off guard by the behavior of the AND,
> OR, etc. operators when applied to integer values.

Yeah, that can happen, but where does the fault lie there?

> So my description might go a bit more into detail about using those operators.

That was a concise description, more hand-holding could be added, and that
is apparently what Dan was doing.  But I would advise against adding more
complexity, when trying to explain how simple it is!

<g>
LFS
Author
12 May 2005 3:35 PM
Jonathan Wood
Larry,

> > Okay, but as you state, they are acting on individual bits. That's what
I've
> > always described as bitwise. To me, logical refers to a boolean state.
What
> > names would you use to distinguish between the two?
>
> Consider:  What is the logical outcome of this premis?

Well, it was a question, actually.

> As you see the meaning of the term 'logical' is a bit too wide to try to
tie it
> to specific operations.  Why not just numerical, and boolean?

I was using the term "logical" pretty much interchangeably with Boolean. So
either term probably works for me. If I choose that term instead, then I'd
call the two types of operations bitwise and Boolean.

> That was a concise description, more hand-holding could be added, and that
> is apparently what Dan was doing.  But I would advise against adding more
> complexity, when trying to explain how simple it is!

I agree. Or at least separate the bitwise stuff into a separate tutorial for
those people who do not know that stuff and want to learn.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Author
12 May 2005 6:50 PM
Larry Serflaten
"Jonathan Wood" <jw***@softcircuits.com> wrote

> I was using the term "logical" pretty much interchangeably with Boolean. So
> either term probably works for me. If I choose that term instead, then I'd
> call the two types of operations bitwise and Boolean.

Yeah, that is what I meant...

LFS
Author
12 May 2005 4:20 PM
Dan Barclay
"Larry Serflaten" <serfla***@usinternet.com> wrote in message
news:OndBdeoVFHA.1404@TK2MSFTNGP09.phx.gbl...
>
quote>
>
> The sentence, "For tests only..." is clearly a misleading statement:
>
> Debug.Print CBool(1)
>
> Where is there any sort of 'test' in that???  Yet it results in a True or
> False result
> depending on the numerical value used....

The numerical value must be "tested" to see which logical value to assign.
The value of logicals is determined by testing, not by calculation.

But, call it what you want.  I needed a word to use.  I used the term "test"
because it makes sense to most people and it is distinct from other
evaluations.  If you want to use the term "calculate" (or something else),
that's fine.  The key point is that in this
"test/calculation/determination/conversion", Zero is False, everything else
is True.

Dan
Author
12 May 2005 4:35 PM
Dan Barclay
Johathan,

BTW, the major reason I wrote that paper was to document the *behavior* of
logical expressions to highlight one of the major issues with VB.Net for the
VB team.  It was a summary of many answers given in newsgroups over the
years, answering questions on their behavior.

At the time I wrote that, VB.Net logical expression evaluation did NOT work
that way.   Valid logical expressions from VB6 could provide completely
different results in VB.Net, and not show an error in either.

The VB *dev team* did not really seem to understand how the expression
evaluator had worked for years.

VB.Net logical expression evaluation was changed after the MVP summit the
following spring.  Unfortunately, instead of recognizing the core language
problem, they only fixed a couple of symptoms like this.

Dan


Show quote
"Jonathan Wood" <jw***@softcircuits.com> wrote in message
news:%231kRlfmVFHA.628@tk2msftngp13.phx.gbl...
> Karl,
>
>> Simply put...  Every other language is wrong. <g>
>>
>> Here's a more in-depth discussion/explanation:
>>
>>   Microsoft Basic Logical Expression Evaluation
>>   http://vb.mvps.org/tips/truth.asp
>
> I can't for the life of me understand why he continues to call VB's AND,
> OR,
> XOR, etc. operators *logical*. They are bitwise, and that is why True
> should
> be -1 in VB. If VB supported logical AND, OR, XOR, etc. operators, then it
> wouldn't matter if True was -1 or 1, or 45 for that matter.
>
> --
> Jonathan Wood
> SoftCircuits
> http://www.softcircuits.com
> Available for consulting: http://www.softcircuits.com/jwood/resume.htm
>
>
Author
12 May 2005 5:14 PM
Jonathan Wood
Dan,

> BTW, the major reason I wrote that paper was to document the *behavior* of
> logical expressions to highlight one of the major issues with VB.Net for
the
> VB team.  It was a summary of many answers given in newsgroups over the
> years, answering questions on their behavior.
>
> At the time I wrote that, VB.Net logical expression evaluation did NOT
work
> that way.   Valid logical expressions from VB6 could provide completely
> different results in VB.Net, and not show an error in either.

Yes, I'm aware of the difference, and also that this was at least part of
the reason you felt the need for the article. I guess I view the issue from
a slightly different angle, even though we both appear to understand how
those operators work.

> The VB *dev team* did not really seem to understand how the expression
> evaluator had worked for years.

Heheh, well, that's hard to believe, but I understand the frustration of
dealing with them at times.

> VB.Net logical expression evaluation was changed after the MVP summit the
> following spring.  Unfortunately, instead of recognizing the core language
> problem, they only fixed a couple of symptoms like this.

I was there. While I thought it was great that the language would be given
both Boolean and bitwise operators, I thought the approach they ended up
with left much to be desired.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm
Author
12 May 2005 5:49 PM
Karl E. Peterson
Jonathan Wood wrote:
>> VB.Net logical expression evaluation was changed after the MVP
>> summit the following spring.  Unfortunately, instead of recognizing
>> the core language problem, they only fixed a couple of symptoms like
>> this.
>
> I was there. While I thought it was great that the language would be
> given both Boolean and bitwise operators, I thought the approach they
> ended up with left much to be desired.

I hereby nominate this for the "2005 Understatement of the Year" award.

Do I hear any seconds? <g>
--
Working Without a .NET?
http://classicvb.org/petition
Author
13 May 2005 3:16 PM
Dan Barclay
Show quote
"Karl E. Peterson" <k***@mvps.org> wrote in message
news:%23zdeurxVFHA.2448@TK2MSFTNGP12.phx.gbl...
> Jonathan Wood wrote:
>>> VB.Net logical expression evaluation was changed after the MVP
>>> summit the following spring.  Unfortunately, instead of recognizing
>>> the core language problem, they only fixed a couple of symptoms like
>>> this.
>>
>> I was there. While I thought it was great that the language would be
>> given both Boolean and bitwise operators, I thought the approach they
>> ended up with left much to be desired.
>
> I hereby nominate this for the "2005 Understatement of the Year" award.
>
> Do I hear any seconds? <g>

<chuckle>  Yea. 2nd.

He's got it right though, unlike some others who still don't "get it".

I'll try to compete for that award:

It's unfortunate that MS never acknoledged or addressed the core problem of
language stability.

Dan <sigh... after 4 years they still don't "get it">
Author
16 May 2005 10:58 PM
Karl E. Peterson
Dan Barclay wrote:
Show quote
> "Karl E. Peterson" <k***@mvps.org> wrote in message
> news:%23zdeurxVFHA.2448@TK2MSFTNGP12.phx.gbl...
>> Jonathan Wood wrote:
>>>> VB.Net logical expression evaluation was changed after the MVP
>>>> summit the following spring.  Unfortunately, instead of recognizing
>>>> the core language problem, they only fixed a couple of symptoms
>>>> like this.
>>>
>>> I was there. While I thought it was great that the language would be
>>> given both Boolean and bitwise operators, I thought the approach
>>> they ended up with left much to be desired.
>>
>> I hereby nominate this for the "2005 Understatement of the Year"
>> award.
>>
>> Do I hear any seconds? <g>
>
> <chuckle>  Yea. 2nd.
>
> He's got it right though, unlike some others who still don't "get it".
>
> I'll try to compete for that award:
>
> It's unfortunate that MS never acknoledged or addressed the core
> problem of language stability.

Unfortunate, yes... <sigh>  Yeah, that'd have to be tossed into the running, there.

Seems *some* at MSFT are starting to get it...
http://blogs.msdn.com/ericgu/archive/2005/05/09/415751.aspx

Probably too late for the company to survive, though. <shrug>
--
Working Without a .NET?
http://classicvb.org/petition
Author
13 May 2005 3:20 PM
Dan Barclay
"Jonathan Wood" <jw***@softcircuits.com> wrote in message


>> The VB *dev team* did not really seem to understand how the expression
>> evaluator had worked for years.
>
> Heheh, well, that's hard to believe, but I understand the frustration of
> dealing with them at times.

Yes, it was hard to believe.  The guys I talked to (outside the meeting
room) simply didn't understand it.  Rob wanted to talk to me about it and I,
err... "explained" what I was talking about.  It was as if he hadn't
considered the differences or what they meant.

I had one of the doc guys hit me up for a copy of this paper at the meeting!

Dan
Author
11 May 2005 4:34 PM
Bob Butler
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:F3A39DDB-C628-4951-A6E1-222185C2BCD7@microsoft.com
> This has been bugging me for a while.  Why is VB like the only
> language that treats the boolean value of True as the integer -1?
> C/C++, C#, and Java, to name a few, all treat it as the integer 1.
> This gets to be annoying when you are trying to set the value of a
> checkbox to 1.  When you set the value to True, you get an error
> because -1 (boolean True) is not a valid property value for the
> CheckBox.Value property.  In this case, the easiest way around this
> is to wrap the boolean with Abs() to force it to output a 1 instead
> of a -1.  Why did MS ever design VB this way?

Because VB does not have logical operators, only binary operators.  The
keywords Not, Or and And wok on the individual bits in each operand.  The
numeric value -1 has all bits on, or "true", which is the binary equivalent
of "Not False".  As long as you treat boolean values strictly as boolean and
don't try to convert to numeric you won't have a problem.

In a language with both logical and binary operators, like C, there are
reasons for making True=1 but neither 1 or -1 is really better than the
other as long as you are consistent within the language.

BTW, the easiest way to set a checkbox value correctly is
checkbox1.Value = IIF(testvalue, vbChecked, vbUnchecked)

That will let you use +1 or -1 or any other non-zero value while also using
the constants for readability and eliminating the hack of converting boolean
to numeric.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
11 May 2005 6:16 PM
Chris Lieb
I never realized that the operators in VB were all bitwise.  I had always
figured that they were logical operators since you can't do things like bit
shifts (<< and >>).  At least now I know why True = -1.  Thanks everyone.

Show quote
"Bob Butler" wrote:

> "Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
> news:F3A39DDB-C628-4951-A6E1-222185C2BCD7@microsoft.com
> > This has been bugging me for a while.  Why is VB like the only
> > language that treats the boolean value of True as the integer -1?
> > C/C++, C#, and Java, to name a few, all treat it as the integer 1.
> > This gets to be annoying when you are trying to set the value of a
> > checkbox to 1.  When you set the value to True, you get an error
> > because -1 (boolean True) is not a valid property value for the
> > CheckBox.Value property.  In this case, the easiest way around this
> > is to wrap the boolean with Abs() to force it to output a 1 instead
> > of a -1.  Why did MS ever design VB this way?
>
> Because VB does not have logical operators, only binary operators.  The
> keywords Not, Or and And wok on the individual bits in each operand.  The
> numeric value -1 has all bits on, or "true", which is the binary equivalent
> of "Not False".  As long as you treat boolean values strictly as boolean and
> don't try to convert to numeric you won't have a problem.
>
> In a language with both logical and binary operators, like C, there are
> reasons for making True=1 but neither 1 or -1 is really better than the
> other as long as you are consistent within the language.
>
> BTW, the easiest way to set a checkbox value correctly is
> checkbox1.Value = IIF(testvalue, vbChecked, vbUnchecked)
>
> That will let you use +1 or -1 or any other non-zero value while also using
> the constants for readability and eliminating the hack of converting boolean
> to numeric.
>
> --
> Reply to the group so all can participate
> VB.Net: "Fool me once..."
>
>
Author
11 May 2005 4:35 PM
Mike D Sutton
> This has been bugging me for a while.  Why is VB like the only language that
> treats the boolean value of True as the integer -1?  C/C++, C#, and Java, to
> name a few, all treat it as the integer 1.  This gets to be annoying when you
> are trying to set the value of a checkbox to 1.  When you set the value to
> True, you get an error because -1 (boolean True) is not a valid property
> value for the CheckBox.Value property.  In this case, the easiest way around
> this is to wrap the boolean with Abs() to force it to output a 1 instead of a
> -1.  Why did MS ever design VB this way?

True = 0xFFFF which when coerced into an Integer == -1:

'***
Debug.Print Hex(True) ' Prints: FFFF
Debug.Print &HFFFF    ' Prints: -1
'***

If you're checking the value of a checkbox then either compare against the constant vbChecked, or just let type
conversion do it for you:

'***
If (Check1.Checked = vbChecked) Then ...
If (Check1.Checked) Then ...
'***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
11 May 2005 4:40 PM
alpine
On Wed, 11 May 2005 09:22:04 -0700, "Chris Lieb"
<ChrisL***@discussions.microsoft.com> wrote:

>This has been bugging me for a while.  Why is VB like the only language that
>treats the boolean value of True as the integer -1?  C/C++, C#, and Java, to
>name a few, all treat it as the integer 1.  This gets to be annoying when you
>are trying to set the value of a checkbox to 1.  When you set the value to
>True, you get an error because -1 (boolean True) is not a valid property
>value for the CheckBox.Value property.  In this case, the easiest way around
>this is to wrap the boolean with Abs() to force it to output a 1 instead of a
>-1.  Why did MS ever design VB this way?


VB treats anything that is non-zero as true so, it is the other
languages that are messed up.

Your problem is that you are attempting to use true/false logic
assignments with a checkbox.  You should be using the constants
vbChecked and vbUnChecked when working with checkboxes.

HTH,
Bryan
____________________________________________________________
New Vision Software                   "When the going gets weird,"
Bryan Stafford                      "the weird turn pro."
alpine_don'tsendspam@mvps.org     Hunter S. Thompson - 
Microsoft MVP-Visual Basic     Fear and Loathing in LasVegas
Author
11 May 2005 6:14 PM
Rick Rothstein
>  Your problem is that you are attempting to use true/false logic
> assignments with a checkbox.  You should be using the constants
> vbChecked and vbUnChecked when working with checkboxes.

Correct! And the reason is that the Value property of the CheckBox takes
one of three possible values... vbChecked, vbUnChecked and vbGrayed, not
the two that a Boolean would indicate.

Rick - MVP
Author
12 May 2005 6:20 AM
J French
On Wed, 11 May 2005 14:14:39 -0400, "Rick Rothstein"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote:

>>  Your problem is that you are attempting to use true/false logic
>> assignments with a checkbox.  You should be using the constants
>> vbChecked and vbUnChecked when working with checkboxes.

>Correct! And the reason is that the Value property of the CheckBox takes
>one of three possible values... vbChecked, vbUnChecked and vbGrayed, not
>the two that a Boolean would indicate.

>Rick - MVP

Spot on
- I was wondering when someone would point that out
Author
12 May 2005 9:00 AM
Dave
False = NOT True
True = 0 therefore
False = NOT 0 = FFFF FFFF FFFF ...
in twos complement all Fs = -1

See http://burks.brighton.ac.uk/burks/foldoc/42/120.htm for an explaination
of twos complement.

Dave.

Show quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:F3A39DDB-C628-4951-A6E1-222185C2BCD7@microsoft.com...
> This has been bugging me for a while.  Why is VB like the only language
> that
> treats the boolean value of True as the integer -1?  C/C++, C#, and Java,
> to
> name a few, all treat it as the integer 1.  This gets to be annoying when
> you
> are trying to set the value of a checkbox to 1.  When you set the value to
> True, you get an error because -1 (boolean True) is not a valid property
> value for the CheckBox.Value property.  In this case, the easiest way
> around
> this is to wrap the boolean with Abs() to force it to output a 1 instead
> of a
> -1.  Why did MS ever design VB this way?
>
> --
> Chris Lieb
> UPS CACH, Hodgekins, IL
> Tech Support Group - Systems/Apps
Author
12 May 2005 12:32 PM
Rick Rothstein
> False = NOT True
> True = 0 therefore
> False = NOT 0 = FFFF FFFF FFFF ...
> in twos complement all Fs = -1

Right idea, but you mixed up your True's and False's...

False = 0
True = Not False

so....

True = Not 0 = FFFF FFFF .....

In Twos Complement, all Fs = -1

Rick - MVP
Author
12 May 2005 3:43 PM
Dave
Congratulations, you win the star prize for spotting the deliberate mistake.

The prize is a copy of VB.NET which I'm sure you'll enjoy.

Show quote
"Rick Rothstein" <rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:eGP2x6uVFHA.3764@TK2MSFTNGP15.phx.gbl...
>> False = NOT True
>> True = 0 therefore
>> False = NOT 0 = FFFF FFFF FFFF ...
>> in twos complement all Fs = -1
>
> Right idea, but you mixed up your True's and False's...
>
> False = 0
> True = Not False
>
> so....
>
> True = Not 0 = FFFF FFFF .....
>
> In Twos Complement, all Fs = -1
>
> Rick - MVP
Author
13 May 2005 11:29 AM
Tony Proctor
It's not the only language! I know of several languages that use True=-1,
and all for the same reason (outlined below by other posts).

As for checkboxes, their value should be one of vbChecked, vbUnchecked, or
vbGrayed, not True (irrespective of the internal value of True).

        Tony Proctor

Show quote
"Chris Lieb" <ChrisL***@discussions.microsoft.com> wrote in message
news:F3A39DDB-C628-4951-A6E1-222185C2BCD7@microsoft.com...
> This has been bugging me for a while.  Why is VB like the only language
that
> treats the boolean value of True as the integer -1?  C/C++, C#, and Java,
to
> name a few, all treat it as the integer 1.  This gets to be annoying when
you
> are trying to set the value of a checkbox to 1.  When you set the value to
> True, you get an error because -1 (boolean True) is not a valid property
> value for the CheckBox.Value property.  In this case, the easiest way
around
> this is to wrap the boolean with Abs() to force it to output a 1 instead
of a
> -1.  Why did MS ever design VB this way?
>
> --
> Chris Lieb
> UPS CACH, Hodgekins, IL
> Tech Support Group - Systems/Apps

AddThis Social Bookmark Button