= operator overloaded in VB6 or VB.NET

C

Chris Dunaway

True is usually -1, because Booleans are usually signed and true is
All Bits On (using two's complement we end up with -1). All bits off,
obviously, is 0. => False.

This may be true of the language, but in my opinion, it is poor coding
practice to use a boolean state and an integer value. The two should not
be mixed.

IMHO

Chris
 
H

Herfried K. Wagner

Hello,

Cor said:
I am Dutch, I think you did know that already.

I didn't know that.

;-)
You know we deal very easy with the English language
because our language is quiet simular with that language
even more than German.

When learning English at school, it was sometimes really hard for me.
The teachers didn't show us the similarity of German and English.
Engligh words are often very similar to German dialects, so it's easy to
remember them.
But English, German and Duch are languages from the North
sea and quiet simular(for who did not know that).

I already knew it.

;-)
I find it strange that you wrote that program sentences
are abstracts for you and in the same way wrote they
are natural.

I knew you would "complain" about this sentence. As a German speakter I
do not have problems to understand the meaning of the words in the code.
Nevertheless, I think of the large number of people in the world who
speak languages that are not similar to the English language. These
people will have really big problems in understanding the basics of our
programming languages.
(I think it is abstract for most German people, that is
normal because German is the major language in
Europe, but not for you).

You are right. I think the keywords are not "typical" Engligh, they are
often short or abbreviations, that's why I didn't say that its natural
language for me. There are similarities, I like them, but its not a
natural language.

;-)))
But we agree and I have to say that my discussion is strange.
We both like VB.net because it is so natural (I hated VB till
there was VB.net, I did find the not anymore usable Cobol
the best till now), and on the other hand I want a language
independent program language.

I agree with you.

Regards,
Herfried K. Wagner
 
C

Chris Dunaway

I would suggest that there is no justification for True to be defined
as 1. It should always be -1 since the definition of True is

I would suggest that there is no justification for treating True or False
and integer values at all!

IMHO with Option Strict On, the following code should not compile (and I
haven't tested in VS to see if it does):

Dim a As Boolean = True
Dim b As Integer = 0
Dim y As Integer

y = a And b 'IMHO, this should generate an error.

IMHO, booleans and integers should not be type compatible.

There was a big argument when VB.Net was first released about whether True
should be 1 or -1. I say that True should be True and should have no
integer value at all. It makes no logical sense to me to convert a boolean
value to an integer.

Chris
 
T

Tom Shelton

Tom Spink said:
True

Why should it give a one? A = B = 3 is "A becomes equal to the comparison of
(B = 3)". B = 3, in this instance, results in a boolean expression.

True is usually -1, because Booleans are usually signed and true is All Bits
On (using two's complement we end up with -1). All bits off, obviously, is
0. => False.

First, I totally agree with the respondent Chris, that boolean values should
never be treated as integers... But beyond that - VB was the only language
I ever used that defined true = -1 and false = 0. Most languages define it
as true <> 0, false = 0. Of course most if you do an integer conversion
define the actual value of true as 1.

Tom Shelton
 
C

Cor

Herfried,
Last sentence on this topic.
We agree. We know.
I did some studie about North Sea languages.
Just one word about it for you, once we had one language, so it are not
German Dialects, but the "basic" language LOL. (Till the bible was wroten by
Luther)
Cor
 
C

Cor

Tom,
Wrong,
Primarly we did use bit + bit = 0 both bits are equal
bit + bit = 1, bits are not equal.

I agree that -1 is stupid, but it has nothing to do with VB, it is a
behaviour of the object and in all languages that uses window objects the
same.

But I do not have a better sollution.

Cor
 
T

Tom Spink

as true <> 0, false = 0.

And something defined as not equal to zero is not zero?

Hence, True = Not 0 => Not &H00, => &HFF => -1 (Signed)

--
Happy to help,
-- Tom Spink
([email protected])

"Go down with your server"

http://dotnetx.betasafe.com >> On The Mend

Please respond to the newsgroup,
so all can benefit
 
R

Rainer Schwenkreis

Hello Chris,

Chris Dunaway said:
...
This may be true of the language, but in my opinion, it is poor coding
practice to use a boolean state and an integer value. The two should not
be mixed.

The expression b=3 is of type boolean in VB if you convert TRUE to integer
you will get a value
of -1. In the ancient Versions of Basic there was no boolean so a boolean
operator returned an integer (0 or -1).

since the type of a is not stated explicit it is good coding style according
to you if a is dimed as boolean.
 
R

Rainer Schwenkreis

Hello Tom,


Tom Shelton said:
...
First, I totally agree with the respondent Chris, that boolean values should
never be treated as integers... But beyond that - VB was the only language
I ever used that defined true = -1 and false = 0. Most languages define it
as true <> 0, false = 0. Of course most if you do an integer conversion
define the actual value of true as 1.

Thats true for C and it's relatives. Strong typed Languages define boolean
as either true or false and nothing else.

The reason for the -1 in Basic is that
1. like in C there is no boolean (in original Basic) the if expression tests
against <> 0
2. unlike C there is only one AND and one OR that is used for boolean
operations
and for bit masking operations. C has && and & for and.
 
C

Cor

Tony,
I did not deal in the discussion, till now but:
0 = False and not False = True.
This has always been in every language and every computer.
That is the basic of programming.

I don't know but I think that even -0 is True, but for me is that bullshit.
That discussion I had once, but I always have to cry when I think about such
a discussion.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top