473,326 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Overloading of the unary ++ operator in VB.net

Overloading of the unary ++ operator in vb.net is not working. It show error:
Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change developing
language to C#? Any suggestion?
Jun 27 '08 #1
15 1987
On 2008-04-29, VB Developer <VB*********@discussions.microsoft.comwrote:
Overloading of the unary ++ operator in vb.net is not working. It show error:
Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change developing
language to C#? Any suggestion?
++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.

--
Tom Shelton
Jun 27 '08 #2
"VB Developer" <VB*********@discussions.microsoft.comschrieb
Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?
Yes, don't use "++". "++" is not a valid operator; but not only with
overloading. It does not exist.
C# is working fine for overloading ++, and do I need to change
developing language to C#?
You can't. You are VB Developer.
Armin

Jun 27 '08 #3
Tom Shelton wrote:
On 2008-04-29, VB Developer <VB*********@discussions.microsoft.com>
wrote:
>Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change
developing language to C#? Any suggestion?

++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.
Or one of +=, *=, &= and so on, which the help/error message seems to miss
out.

Andrew
Jun 27 '08 #4
On 2008-04-29, Andrew Morton <ak*@in-press.co.uk.invalidwrote:
Tom Shelton wrote:
>On 2008-04-29, VB Developer <VB*********@discussions.microsoft.com>
wrote:
>>Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change
developing language to C#? Any suggestion?

++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.

Or one of +=, *=, &= and so on, which the help/error message seems to miss
out.

Andrew
hmmm, you are correct :) It does seem to leave those out.

--
Tom Shelton
Jun 27 '08 #5
"Andrew Morton" <ak*@in-press.co.uk.invalida écrit dans le message de
groupe de discussion : 67*************@mid.individual.net...
Tom Shelton wrote:
>On 2008-04-29, VB Developer <VB*********@discussions.microsoft.com>
wrote:
>>Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change
developing language to C#? Any suggestion?

++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.

Or one of +=, *=, &= and so on, which the help/error message seems to
miss out.

Andrew
Similarly I would say that += etc... doesn't really exists. This is just a
shortcut notation... What if you try just + or whatever fit your needs ?

You may want to explain what you are trying to do...
--
Patrice

Jun 27 '08 #6
+= is not work too.

Code:
Public Shared Operator +=(ByVal bi As Integer) As Integer
....................

End Operator

Give the same error above.

Please check it before post yours.


"Tom Shelton" wrote:
On 2008-04-29, Andrew Morton <ak*@in-press.co.uk.invalidwrote:
Tom Shelton wrote:
On 2008-04-29, VB Developer <VB*********@discussions.microsoft.com>
wrote:
Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change
developing language to C#? Any suggestion?

++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.
Or one of +=, *=, &= and so on, which the help/error message seems to miss
out.

Andrew

hmmm, you are correct :) It does seem to leave those out.

--
Tom Shelton
Jun 27 '08 #7
Patrice wrote:
"Andrew Morton" <akm@a écrit dans le message
>Or one of +=, *=, &= and so on, which the help/error message seems
to miss out.

Andrew

Similarly I would say that += etc... doesn't really exists. This is
just a shortcut notation... What if you try just + or whatever fit
your needs ?
You may want to explain what you are trying to do...
/I/'m trying to let the OP know there's no ++ operator in VB.NET... :-)

Andrew
Jun 27 '08 #8
On 2008-04-29, VB Developer <VB*********@discussions.microsoft.comwrote:
+= is not work too.

Code:
Public Shared Operator +=(ByVal bi As Integer) As Integer
...................

End Operator

Give the same error above.

Please check it before post yours.

Actually, looking in the docs, +=, -=, etc are not valid for
overloading, so the error message is perfectly correct. You would have
to overload the +:

Public Shared Operator +(ByVal bi As Integer) As Integer
End Sub

+= and friends are compiler shortcuts - not actual operators.
--
Tom Shelton
Jun 27 '08 #9
"VB Developer" <VB*********@discussions.microsoft.comschrieb
+= is not work too.

Code:
Public Shared Operator +=(ByVal bi As Integer) As Integer
...................

End Operator

Give the same error above.

Please check it before post yours.
See Patrice' reply. The "real" operator is "+". You will be able to use
"dest += value" just like "dest = dest + value"
Armin

Jun 27 '08 #10

I want to transfer C# code to VB.net code. I know now it is impossible at
some part and except you change original code such as ++ to +1.

"Patrice" wrote:
"Andrew Morton" <ak*@in-press.co.uk.invalida écrit dans le message de
groupe de discussion : 67*************@mid.individual.net...
Tom Shelton wrote:
On 2008-04-29, VB Developer <VB*********@discussions.microsoft.com>
wrote:
Overloading of the unary ++ operator in vb.net is not working. It
show error: Operator declaration must be one of: +, -, *, \, /, ^,
&, Like, Mod, And, Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType,
IsTrue, IsFalse.

Is there any way can to get rid of this error?

C# is working fine for overloading ++, and do I need to change
developing language to C#? Any suggestion?

++ is not an operator in VB.NET. As the error says, it must be one of
the listed operators.
Or one of +=, *=, &= and so on, which the help/error message seems to
miss out.

Andrew

Similarly I would say that += etc... doesn't really exists. This is just a
shortcut notation... What if you try just + or whatever fit your needs ?

You may want to explain what you are trying to do...
--
Patrice

Jun 27 '08 #11
This is just to port code and an attempt to avoid changing ++ ?

Depending on the reason for this port you could :
- compile the C# code into a DLL so that you can reuse this code without
even having to port
- also I've heard about translators being able to take source code in a
particular language and translate it to another language (try googling for
this)

Of course if you really want to this by hand you'll have anyway much bigger
changes than that...
--
Patrice

"VB Developer" <VB*********@discussions.microsoft.coma écrit dans le
message de groupe de discussion :
DD**********************************@microsoft.com...
>
I want to transfer C# code to VB.net code. I know now it is impossible at
some part and except you change original code such as ++ to +1.


Jun 27 '08 #12
On 2008-04-29, VB Developer <VB*********@discussions.microsoft.comwrote:
>
I want to transfer C# code to VB.net code. I know now it is impossible at
some part and except you change original code such as ++ to +1.
Yep. VB.NET doesn't support pre/post increment/decrement operators.
The closest you get is:

b += 1

or

b -= 1

And that is just a shortcut for:

b = b + 1

or

b = b -1

One more reson to prefer C# :)

--
Tom Shelton
Jun 27 '08 #13
"VB Developer" <VB*********@discussions.microsoft.comschrieb:
Overloading of the unary ++ operator in vb.net is not working. It show
error:
Operator declaration must be one of: +, -, *, \, /, ^, &, Like, Mod, And,
Or, Xor, Not, <<, >>, =, <>, <, <=, >, >=, CType, IsTrue, IsFalse.

Is there any way can to get rid of this error?
Overload the '+' operator. You may want to handle the case of
incrementation "by one" differently.
C# is working fine for overloading ++, and do I need to change developing
language to C#? Any suggestion?
Why would you want to overload this operator? Note that this operator is
syntactic sugar, as is '+='. VB does not even support the '++' shorthand
syntax.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 27 '08 #14
"Tom Shelton" <to*********@YOUKNOWTHEDRILLcomcast.netschrieb:
>I want to transfer C# code to VB.net code. I know now it is impossible
at
some part and except you change original code such as ++ to +1.

Yep. VB.NET doesn't support pre/post increment/decrement operators.
The closest you get is:

b += 1

or

b -= 1

And that is just a shortcut for:

b = b + 1

or

b = b -1

One more reson to prefer C# :)
Well, opinions seem to differ. I don't see any reason for an additional way
to achieve a certain thing which only saves a few keystrokes but requires
additional keystrokes if incrementation/decrementation should be changed
from 1 to another value.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jun 27 '08 #15
On 2008-05-01, Herfried K. Wagner [MVP] <hi***************@gmx.atwrote:
"Tom Shelton" <to*********@YOUKNOWTHEDRILLcomcast.netschrieb:
>>I want to transfer C# code to VB.net code. I know now it is impossible
at
some part and except you change original code such as ++ to +1.

Yep. VB.NET doesn't support pre/post increment/decrement operators.
The closest you get is:

b += 1

or

b -= 1

And that is just a shortcut for:

b = b + 1

or

b = b -1

One more reson to prefer C# :)

Well, opinions seem to differ. I don't see any reason for an additional way
to achieve a certain thing which only saves a few keystrokes but requires
additional keystrokes if incrementation/decrementation should be changed
from 1 to another value.
it's the pre/post thing that comes in handy sometimes... Not
necessarily the shortcut for += 1.

--
Tom Shelton
Jun 27 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: PKH | last post by:
This is a part of an autopointer template i'm using. I originally had a Get() member that returned the pointer, but thought it would nice to be able to use the -> operator. The question is why...
2
by: Ook | last post by:
This is a few ways I've seen to overload operator+. I can understand that you would want to pass a reference to the function if you wanted to change some of the data elements of the class, but in...
0
by: Leszek Taratuta | last post by:
Hello, I have the following code snippet that overloads the "-" operator: // unary public static Vector operator -( Vector v ) { return new Vector( -v.X, -v.Y ); }
5
by: Jerry Fleming | last post by:
As I am newbie to C++, I am confused by the overloading issues. Everyone says that the four operators can only be overloaded with class member functions instead of global (friend) functions: (), ,...
6
by: Matthew Cook | last post by:
I would like to overload the unary minus operator so that I can negate an instance of a class and pass that instance to a function without creating an explicit temporary variable. Here is an...
19
by: Jess | last post by:
Hello, After seeing some examples about operator overloading, I'm still a bit confused about the general syntax. The following is what I think, not sure whether it's correct. 1. For a unary...
8
by: Wayne Shu | last post by:
Hi everyone, I am reading B.S. 's TC++PL (special edition). When I read chapter 11 Operator Overloading, I have two questions. 1. In subsection 11.2.2 paragraph 1, B.S. wrote "In particular,...
2
by: jimzat | last post by:
I am trying to simulate the execution of some PLC ladder logic in python. I manually modified the rungs and executed this within python as a proof of concept, but I'd like to be able to skip the...
1
by: haderika | last post by:
Hey, I'm having trouble overloading the ~ operator (the determinant of the matrix) in a case of 2x2 matrices. So i have a matrix class, with the constructor, overloading +, += and ~ operators. the...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.