Why Not True = True

# Thread: Why Not True = True

1. Member
Join Date
Dec 1969
Posts
31

## Why Not True = True

Can anyone tell me why VB does stupid thing like this?<BR> x = 1<BR> y = Not x<BR> x = CBool(x)<BR> y = CBool(y)<BR>Both x and y are evaluated as True?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Wrong question...

You should have asked "What is the value of the expression (Not 1) ?"<BR><BR>Did you try to find out???<BR><BR>And then, after you found out, you would ask the question "So what is the value of CINT(True) ?" <BR><BR>And you&#039;d try to find that out.<BR><BR>And *then* I think you&#039;d understand it.<BR><BR>You are *assuming* that NOT is *always* a boolean operator in VBScript. Sorry. Wrong assumption! When used with integers, it is a bitwise operator. Just as OR, AND, XOR, etc., are all bitwise operators when used with integers.<BR><BR>

3. ks
Senior Member
Join Date
Dec 1969
Posts
734

## RE: Why Not True = True

This is perhaps the dumpest thing about VB. In VB, not 1 is -2, not 2 is -3, etc and vice versa. The only number that holds true for not ture = false is -1.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## It is *NOT* dumb...*NOT* stupid...

When used with numbers, the NOT operator produces the ONE&#039;S COMPLEMENT of the number!<BR><BR>So 1, in binary form is (limited to 8 bits) 00000001<BR><BR>And the one&#039;s complement of that (NOT 1 in VBS) is 11111110<BR><BR>And that number (extended to 16 or 32 bits as an integer) is -2!<BR><BR>If you *need* to get a BOOLEAN value, then do<BR><BR>NOT( CBOOL( num ) )<BR><BR>Convert the number to a boolean *first* and then NOT becomes a boolean operator instead of a bitwise operator.<BR><BR>

5. Member
Join Date
Dec 1969
Posts
31

## RE: It is *NOT* dumb...*NOT* stupid...

Thanks a lot.

6. ks
Senior Member
Join Date
Dec 1969
Posts
734

## That makes perfect sense <eop>

.

7. Best VB Coder on Earth Guest

## RE: Wrong question...

Nice One Bill, but try not to talk down to other coders<BR><BR>with less experience. Coding is not a science, it is not even an <BR><BR>art - IT IS A CRAFT, and like all crafts - we all have to serve<BR><BR>our time.<BR><BR>NOW **** OFF YOU SNOBBY *******

8. Senior Member
Join Date
Dec 1969
Posts
1,424

Const Coder = "Best VB Coder on Earth"<BR>Dim result As Boolean<BR>Dim str As String<BR><BR>result = Coder IMP Stupid<BR>str = MsgBox(result, vbInformation+vbOKOnly)

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Ever heard of TEACHING?

Or the old saying "Give a man an answer and he solves today&#039;s problem; give him a methodology and he solves problems all his life"??? (Okay, so it&#039;s usually said with fish and fishing...but the idea is the same.)<BR><BR>You go ahead and, from your lofty and elevated position of knowing all answers, hand out the answers one at a time.<BR><BR>Me, I&#039;d rather tell people *HOW* things work, *WHY* they work, and expecially *HOW TO FIND OUT* both of those on your own. Without the help from a "Best VB Coder" snob who would rather keep them ignorant so he can answer another question from the same person tomorrow.<BR><BR>In this particular instance, I was serious about asking the poster to *try* those activities. TRY doing Response.Write Not 1 and see what you get. Then sit back, scratch your head, and work out *why*, which is usually the more important part, if you really want to learn.<BR><BR>If I seem a little pedantic (okay, a lot pedantic) at times, it is because I *WANT* people to *LEARN*. And if they don&#039;t want to...well, too bad. They don&#039;t have to read me.<BR><BR>I am *NOT* "talking down". I&#039;m "talking the *process* UP"! <BR><BR>Yes, we all have to serve our time. But with just a tiny bit of help from those who would *TEACH* (instead of hand out fish) many people will be able to serve *less* time. I hope.<BR><BR>So, as I said, if *you* don&#039;t like to learn, don&#039;t read me. See the notice at the top of the normal forum page. It applies to me. And, quite thankfully, you.<BR><BR><BR><BR>

#### Posting Permissions

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