?
Solved

Operator Overload VB.net Visual Studio 2005

Posted on 2007-08-02
10
Medium Priority
?
1,107 Views
Last Modified: 2008-01-09
Is there a VB.net way to implement C# operator overload e.g.:

public static bool operator >(Object p1, Object p2) {.....

I tried:

Public Shared Operator >(ByVal p1 As PagePos, ByVal p2 As PagePos) As Boolean

which gives an error - but Public Shared Operator +(... works

                      
                
0
Comment
Question by:John4343
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 27

Expert Comment

by:VBRocks
ID: 19617193
I know that is do-able in C#, because I've done it before.  However I don't think VB can do that.  
Lo siento. :(


0
 
LVL 7

Expert Comment

by:dctuck
ID: 19617205
It can be done in VB - what error are you getting? I've just made a dummy class and it works fine in mine...
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19617224
Oh, you know I just found it written in black and white in my "OOP with Microsoft Visual Basic .NET and
Microsoft Visual C# .NET" book by Robin A Reynolds-Haertle.  

    "Visual Basic .NET doesn't support operator overloading.  Depending on the problem you're solving,
    operator overloading might be a deciding factor in whether you implement the application in Visual  
    Basic or Visual C#."

0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
LVL 7

Expert Comment

by:dctuck
ID: 19617296
VBRocks:

Is that VB.NET or VB2005 - John4343 says he's using 2005, and I've just tried it and it works!
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19617314
Oh, good point.  I think it is a 2003 book.  Can you post an example?

0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 19617316
Hi John4343;

To do this in VB .Net if you Overload the > operator you must also Overload the < operator. If you only do 1 you will get an error you must do both as shown below.

Public Shared Operator >(ByVal p1 As PagePos, ByVal p2 As PagePos) As Boolean

End Operator

Public Shared Operator <(ByVal p1 As PagePos, ByVal p2 As PagePos) As Boolean

End Operator

Fernando
0
 
LVL 7

Expert Comment

by:dctuck
ID: 19617332
The example that John4343 had posted was correct - the error was probably that described by Fernando just now :)
0
 
LVL 27

Expert Comment

by:VBRocks
ID: 19617342
Very nice.  Thanks!
0
 

Author Comment

by:John4343
ID: 19618569
Thanks.  And of course >= and <= must also be paired.

NOT intuitive.

0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 19618630
Not a problem, glad I was able to help. ;=)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question