Do operators work on a Point structure?  
Author Message
jokara





PostPosted: Fri Jun 04 22:42:34 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure?

I am trying to add 2 points together, and I am not succeeding.
It appears the docs say I need a point and a size, but even that fails
in the copy of VS 2003 I have.

Exactly what are they trying to say here?

http://www.hide-link.com/

Can't I use: pt1 = pt2 + pt3

Or do I need a size: pt1 = pt2 + sz3

The only thing that compiles, is as shown:

pt1 = Point.op_Addition(pt2, sz3)

But that doesn't show in Intellisense, what's going on?

LFS

Visual Studio165  
 
 
Jay





PostPosted: Fri Jun 04 22:42:34 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure? Larry,
Neither VB.NET 2002 nor VB.NET 2003 support overloaded operators. VB.NET
2005 (Whidbey) will however support using & defining overloaded operators!


So for now you will need to explicitly call the operators, as you showed.

> pt1 = Point.op_Addition(pt2, sz3)


> But that doesn't show in Intellisense, what's going on?
You need to turn off the "Hide advanced members" under "Tools - Options -
Text Editor - Basic - General"


Hope this helps
Jay



> I am trying to add 2 points together, and I am not succeeding.
> It appears the docs say I need a point and a size, but even that fails
> in the copy of VS 2003 I have.
>
> Exactly what are they trying to say here?
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDrawingPointClassop_AdditionTopic.asp
>
> Can't I use: pt1 = pt2 + pt3
>
> Or do I need a size: pt1 = pt2 + sz3
>
> The only thing that compiles, is as shown:
>
> pt1 = Point.op_Addition(pt2, sz3)
>
> But that doesn't show in Intellisense, what's going on?
>
> LFS


 
 
Larry





PostPosted: Sat Jun 05 00:26:21 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure?

> Larry,
> Neither VB.NET 2002 nor VB.NET 2003 support overloaded operators. VB.NET
> 2005 (Whidbey) will however support using & defining overloaded operators!

You would think they would say that, instead of:

" In Visual Basic, you can use the operators defined by a type, but you cannot define your own."

That is what is on the page, and it is misleading. The 'you can use' should not be on that page....

:-(
LFS
 
 
hirf-spam-me-here





PostPosted: Sat Jun 05 08:33:31 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure?
>> Neither VB.NET 2002 nor VB.NET 2003 support overloaded operators. VB.NET
>> 2005 (Whidbey) will however support using & defining overloaded operators!
>
> You would think they would say that, instead of:
>
> " In Visual Basic, you can use the operators defined by a type, but you cannot define your own."
>
> That is what is on the page, and it is misleading. The 'you can use' should not be on that page....

Mhm... An operator is only a special procedure, and you can call this
procedure from VB.NET ;-). If a language's addition operator is not
'+', and instead it's 'ADD', then documentation will be misleading
too...

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
 
 
Jay





PostPosted: Sat Jun 05 08:34:20 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure? Larry,
The "you can use" means you can call the sub directly as you have found, I
agree it is misleading, as it does not support using the operator itself.

Hope this helps
Jay



>

> > Larry,
> > Neither VB.NET 2002 nor VB.NET 2003 support overloaded operators. VB.NET
> > 2005 (Whidbey) will however support using & defining overloaded
operators!
>
> You would think they would say that, instead of:
>
> " In Visual Basic, you can use the operators defined by a type, but you
cannot define your own."
>
> That is what is on the page, and it is misleading. The 'you can use'
should not be on that page....
>
> :-(
> LFS


 
 
Larry





PostPosted: Sat Jun 05 10:23:28 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure?

> > " In Visual Basic, you can use the operators defined by a type, but you cannot define your own."
> >
> > That is what is on the page, and it is misleading. The 'you can use' should not be on that page....
>
> Mhm... An operator is only a special procedure, and you can call this
> procedure from VB.NET ;-).

Where do you get that?

//000048: A = 1
IL_0001: ldc.i8 0x1
IL_000a: stloc.0
//000049: B = 2
IL_000b: ldc.i8 0x2
IL_0014: stloc.1
//000050: C = A + B
IL_0015: ldloc.0
IL_0016: ldloc.1
IL_0017: add.ovf
IL_0018: stloc.2

Add.ovf is not a special procedure of any given data type.
If we were talking about a reference type, then of course, it has
to a procedure, but we're not, we are talking about a value type
so I would think any defined operators would be candidates
for inlining the code....


> If a language's addition operator is not
> '+', and instead it's 'ADD', then documentation will be misleading
> too...


I was looking at the "Point Addition Operator" Page, that indicates
that such an operation is possible using the 'operator' as would be
expected. The text goes on to say 'you can use' regaurdless of
whatever else it says. I would (and did) suggest that it should not
use those words, that it should say something more like:

"The Point addition operator is not supported in Visual Basic."

It could also add, what you said, "To add two points together,
call the op_Addition method from your code.

How does their generic remark help the user? (its the same remark
as the other common operators) It is actually a source of
confusion when the remarks say 'you can use' but the reality
is that you cannot.

I already suggested they change the wording, so I am moving on,
no reply is necessary.... :-)

LFS


 
 
Jay





PostPosted: Sat Jun 05 13:58:18 CDT 2004 Top

Visual Basic [VB] >> Do operators work on a Point structure? Larry,
> Add.ovf is not a special procedure of any given data type.
> If we were talking about a reference type, then of course, it has
> to a procedure, but we're not, we are talking about a value type
> so I would think any defined operators would be candidates
> for inlining the code....
Your leaving out one minor point. Int32 (Integer) is a "native" IL value
type, in that there are specific IL instructions for Integers. Where as
Point is simply a value type.

If you look at System.Int32 you will not find an op_Add, where as on
System.Drawing.Point, there is an op_Add.

The compiler has to treat Integer differently then it does Point (the
difference being having specific IL instructions, not whether its a value
type or a reference type). Adding support for overloading operators (the
op_Add routines) is above & beyond what is needed for the "native" IL value
& reference types. (Reference types such as Array & String). I hope you
agree if the compiler did not support the "native" IL types, you would have
an extremely limited compiler ;-)

Hope this helps
Jay




>

> > > " In Visual Basic, you can use the operators defined by a type, but
you cannot define your own."
> > >
> > > That is what is on the page, and it is misleading. The 'you can use'
should not be on that page....
> >
> > Mhm... An operator is only a special procedure, and you can call this
> > procedure from VB.NET ;-).
>
> Where do you get that?
>
> //000048: A = 1
> IL_0001: ldc.i8 0x1
> IL_000a: stloc.0
> //000049: B = 2
> IL_000b: ldc.i8 0x2
> IL_0014: stloc.1
> //000050: C = A + B
> IL_0015: ldloc.0
> IL_0016: ldloc.1
> IL_0017: add.ovf
> IL_0018: stloc.2
>
> Add.ovf is not a special procedure of any given data type.
> If we were talking about a reference type, then of course, it has
> to a procedure, but we're not, we are talking about a value type
> so I would think any defined operators would be candidates
> for inlining the code....
>
>
> > If a language's addition operator is not
> > '+', and instead it's 'ADD', then documentation will be misleading
> > too...
>
>
> I was looking at the "Point Addition Operator" Page, that indicates
> that such an operation is possible using the 'operator' as would be
> expected. The text goes on to say 'you can use' regaurdless of
> whatever else it says. I would (and did) suggest that it should not
> use those words, that it should say something more like:
>
> "The Point addition operator is not supported in Visual Basic."
>
> It could also add, what you said, "To add two points together,
> call the op_Addition method from your code.
>
> How does their generic remark help the user? (its the same remark
> as the other common operators) It is actually a source of
> confusion when the remarks say 'you can use' but the reality
> is that you cannot.
>
> I already suggested they change the wording, so I am moving on,
> no reply is necessary.... :-)
>
> LFS
>
>