Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Collection trouble

Status
Not open for further replies.

PsychoCoder

Programmer
May 31, 2006
140
US
In my application I have written my own collection, the class starts like this:

Code:
Public Class Flight : Implements IComparable
Below that is my variable and property declarations then my New method then below that I have:

Code:
Public Function CompareTo(ByVal obj As Object) As Integer
        If Not (TypeOf obj Is Flight) Then
            Throw New ArgumentException
        End If

        Dim f2 As Flight = CType(obj, Flight)
        Dim cmpl As Integer = Me.FlightNumber.CompareTo(f2.FlightNumber)
        If Not (cmpl = 0) Then
            Return cmpl
        End If
        Return Me.SegNumber.CompareTo(f2.SegNumber)
    End Function

but in the Public Class.... line the word IComparable is underlined with the following error:
Code:
Class 'Flight' must implement 'Function CompareTo(obj As Object) As Integer' for interface 'System.IComparable'.

I have a CompareTo As Integer function in the class, the solution wont build because of this error. What am I doing wrong here?

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Found the solution in another message board, had to change my Function declaration to


Code:
Public Function CompareTo(ByVal obj As Object) As Integer [b]Implements IComparable.CompareTo[/b]


The bolded section had to be added (nice thing to remember when Implementing this and other base objects of the .NET Framework)

Senior Qik III, ASP.Net, VB.Net ,SQL Programmer

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"In the new millennium there will be two kinds of business; those on the net and those out of business"

~ Bill Gates ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top