PC Review


Reply
Thread Tools Rating: Thread Rating: 7 votes, 5.00 average.

= operator overloaded in VB6 or VB.NET

 
 
Tom Shelton
Guest
Posts: n/a
 
      15th Jul 2003
steve wrote:
> On Tue, 15 Jul 2003 18:08:42 -0700, "John Davis"
> <(E-Mail Removed)> wrote:
>
>
>>One interesting observation I found is VB6 or VB.NET overloads = opeartor.
>>i.e. = operator has 2 meanings.
>>
>>Case 1: relational operator. In other languages, usually use == instead.
>>If a = b Then statement
>>
>>Case 2: assignment operator
>>a = b
>>
>>Just my observation. Please discuss.
>>

>
>
> vb is pretty cool huh! == has always wound me up, leads to annoying
> errors that don't show up when compiling and are often difficult to
> track down when debugging. Its like the f puzzle. The brain doesn't
> automatically distinguish == from = when looking at code because we
> are used to just = in everyday life.


Not relavent in Java/C#. Compiler catches this because expressions in
if statements must evaluate to a boolean

Tom Shelton

> But is this relevant in non dotnet groups?
>
>


 
Reply With Quote
 
 
 
 
John Davis
Guest
Posts: n/a
 
      16th Jul 2003
One interesting observation I found is VB6 or VB.NET overloads = opeartor.
i.e. = operator has 2 meanings.

Case 1: relational operator. In other languages, usually use == instead.
If a = b Then statement

Case 2: assignment operator
a = b

Just my observation. Please discuss.


 
Reply With Quote
 
 
 
 
Herfried K. Wagner
Guest
Posts: n/a
 
      16th Jul 2003
Hello,

"John Davis" <(E-Mail Removed)> schrieb:
> One interesting observation I found is VB6 or
> VB.NET overloads = opeartor.
> i.e. = operator has 2 meanings.


That's right. It's one of the main reasons why I use VB Classic/VB
..NET.

Notice that an X-post to microsoft.public.vb.controls doesn't make any
sense.

Regards,
Herfried K. Wagner
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
Vincent Wiegel
Guest
Posts: n/a
 
      16th Jul 2003
huh??

"John Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> One interesting observation I found is VB6 or VB.NET overloads = opeartor.
> i.e. = operator has 2 meanings.
>
> Case 1: relational operator. In other languages, usually use == instead.
> If a = b Then statement
>
> Case 2: assignment operator
> a = b
>
> Just my observation. Please discuss.
>
>
>



 
Reply With Quote
 
Jeff Johnson [MVP: VB]
Guest
Posts: n/a
 
      16th Jul 2003

"John Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> One interesting observation I found is VB6 or VB.NET overloads = opeartor.
> i.e. = operator has 2 meanings.


For reference, from the very beginnings of BASIC the = operator has
performed double-duty, although in the Bad Old Days, the Let statement was
required (ick!) for assignments. Fortunately that went away quickly.

(Not that this has anything to do with controls, but I WILL admit that it IS
relevant to both .NET and non-.NET groups, a rarity there....)


 
Reply With Quote
 
Russ Bishop
Guest
Posts: n/a
 
      16th Jul 2003
a = b is short for Let a = b

If a = b is just what it implies - if a.equals(b) = true

The operator can do double duty because its use is non-ambiguous in either
situation. In other cases, + could be ambiguous, so the string concat
operator & was added to provide a non-ambiguous addition method for adding
strings together.

-- russ

"John Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> One interesting observation I found is VB6 or VB.NET overloads = opeartor.
> i.e. = operator has 2 meanings.
>
> Case 1: relational operator. In other languages, usually use == instead.
> If a = b Then statement
>
> Case 2: assignment operator
> a = b
>
> Just my observation. Please discuss.
>
>



 
Reply With Quote
 
steve
Guest
Posts: n/a
 
      16th Jul 2003
On Tue, 15 Jul 2003 23:29:37 -0400, "Jeff Johnson [MVP: VB]"
<(E-Mail Removed)> wrote:

>
>"John Davis" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>
>> One interesting observation I found is VB6 or VB.NET overloads = opeartor.
>> i.e. = operator has 2 meanings.

>
>For reference, from the very beginnings of BASIC the = operator has
>performed double-duty, although in the Bad Old Days, the Let statement was
>required (ick!) for assignments. Fortunately that went away quickly.
>
>(Not that this has anything to do with controls, but I WILL admit that it IS
>relevant to both .NET and non-.NET groups, a rarity there....)
>


but probably not vb groups. Most vb developers would probably think
overloading meant pushing a program to hard <g>

 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      16th Jul 2003
John,
I don't know how many natural languages you speak, but for people who are
familiar with more languages, it is normal that in every language one word
can have more than one meaning.

The place of the word in the full sentence makes is very easy for the human
brain to understand the meaning for the meaning of the word. So that is
possible with the computer too.

Therefore I never understand why they made the ==, &&, || operators.

The "If" word says everything over the meaning and you can use the () if
there is a real problem.

I think the == and things like that are designed by mathematica people with
a very small knowledge natural languages.
A computer language is not anymore only a string of formules.
For that there was Algol and Fortran (And to say that that where languages
is the same as saying HTML and XML are languages).

What I don't understand is why the "then" is still necessary in VB.
But maybe is that for what Herfried says, "VB is so nice readable".

Cor



 
Reply With Quote
 
Tony Proctor
Guest
Posts: n/a
 
      16th Jul 2003
I suspect this is an inheritance from VB's humble beginnings.

As others have already pointed out in this thread, VB also overloads the
And, Or, Xor, and Not operators. They can each be used in a "bitwise"
context, e.g.
x = y And z
or a "logical" context, e.g.
If x<0 Or Y<0 Then

The reason is related to the overloading of the '=' operator. Very simple
languages (as Basic was), especially those that are interpreted, reduce
their complexity by handling conditional expressions using exactly the same
expression analyser as arithmetic expressions, and using a stack-based
evaluator for both [Huh?].

For instance, the above 'If' statement might be evaluated as follows:
push x ' push x on evaluation stack
push 0 ' push 0
test_lt ' compare top 2 elements, and replace by a boolean
push y
push 0
test_lt
or ' combine top 2 elements using bitwise 'Or'

Note that the evaluation uses only bitwise operations. The compiler (or
interpreter) doesn't need to worry about coding jumps, or short-circuiting
evaluation.

This is also the reason why 'True' in VB has the value -1, and not 1 as in
C/C++. Otherwise, the following would not be correct:
False = Not True

Tony Proctor

"John Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> One interesting observation I found is VB6 or VB.NET overloads = opeartor.
> i.e. = operator has 2 meanings.
>
> Case 1: relational operator. In other languages, usually use == instead.
> If a = b Then statement
>
> Case 2: assignment operator
> a = b
>
> Just my observation. Please discuss.
>
>



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      16th Jul 2003
Hello Rainer,
I do not agree with you.

You speak more than one language. So that is not discussable. But lets bring
it back to natural language.

When you say: a is b you means a is equal to b.
Sometimes you mean a is the sum of a and b.
That is natural language.
I did not know that the sentence a=b=3 exist in VB and I agree that when it
is there it should give back a 1 and not an integer result of False or True

You speak German (me too but I cannot write it) and you know that you have
some words that don't exist in English. We can communicate in that
language.

An == operator is not necassery and I hate it in JavaScript that I often
use.
In VB you say.
If b=1 then
a = 1
b = a
end if
It is a nice sentence and you have to be very stupid not to understand it.

Of course we mis for years a=b=c=d and c++ --c but that will change in
future I supose.

When there would be an operator in this sentence I would choise for
a=b?b=c then we should use normal European 2500 years old characters quick
to understand to everybody that knows those characters.

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing operator overloaded class defined in c# Armond VanHeusen Microsoft VB .NET 2 27th Sep 2005 10:44 PM
assignment to overloaded operator << Ian Lazarus Microsoft C# .NET 5 19th Dec 2004 06:26 PM
Consuming operator overloaded c# Nick Microsoft VB .NET 1 2nd Dec 2004 10:04 PM
Assignment operator can NOT be overloaded ! Christian Microsoft C# .NET 2 16th Mar 2004 03:03 PM
Custom overloaded operator? =?Utf-8?B?U2t1dGU=?= Microsoft VC .NET 0 12th Feb 2004 11:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:35 AM.