Home All Groups Group Topic Archive Search About

At least one object must implement IComparable

Author
26 Jul 2006 2:44 PM
fniles
I have a collection inside a class, sometimes when I add to the collection,
I get the error "At least one object must implement IComparable".
What does the error mean ?
Thanks.

Public Class SessionClass
Private Quotes As Collection = New Collection
    Sub NewQuote(ByVal Message As String)
        Dim swError As StreamWriter

        Try
            Quotes.Add(Message) '--> error here
        Catch ex As Exception
            swError = New StreamWriter(Application.StartupPath &
"\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
vbCrLf, True)
            swError.Write(Now & " Session - NewQuote - error = " &
ex.Message)
            swError.Close()
        End Try
    End Sub

Author
26 Jul 2006 5:10 PM
tommaso.gastaldi
hi
Can you report what "Message" contains when you get the exception?

Also can you report what the 2-nd element of the collection contains
at the time of exception?

-tom

PS
I do not see why not to use a simple arraylist here. The collection
uses a keyvalue entry.

fniles ha scritto:

Show quoteHide quote
> I have a collection inside a class, sometimes when I add to the collection,
> I get the error "At least one object must implement IComparable".
> What does the error mean ?
> Thanks.
>
> Public Class SessionClass
> Private Quotes As Collection = New Collection
>     Sub NewQuote(ByVal Message As String)
>         Dim swError As StreamWriter
>
>         Try
>             Quotes.Add(Message) '--> error here
>         Catch ex As Exception
>             swError = New StreamWriter(Application.StartupPath &
> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
> vbCrLf, True)
>             swError.Write(Now & " Session - NewQuote - error = " &
> ex.Message)
>             swError.Close()
>         End Try
>     End Sub
Author
26 Jul 2006 5:42 PM
fniles
Thank you for your reply.

> Can you report what "Message" contains when you get the exception?
ex.Message = At least one object must implement IComparable

> Also can you report what the 2-nd element of the collection contains
> at the time of exception?
I did not catch the value of the 2nd element of the collection when the
program broke, and this error does not happen all the time.
May I know why do you need to know the value of the 2nd element of the
collection ?

> I do not see why not to use a simple arraylist here. The collection
> uses a keyvalue entry.
Can you please tell me why simple arraylist will be better than collection ?
What did you mean by "collection uses a keyvalue entry" ?

Thanks.

<tommaso.gasta***@uniroma1.it> wrote in message
Show quoteHide quote
news:1153933817.292504.65680@m79g2000cwm.googlegroups.com...
> hi
> Can you report what "Message" contains when you get the exception?
>
> Also can you report what the 2-nd element of the collection contains
> at the time of exception?
>
> -tom
>
> PS
> I do not see why not to use a simple arraylist here. The collection
> uses a keyvalue entry.
>
> fniles ha scritto:
>
>> I have a collection inside a class, sometimes when I add to the
>> collection,
>> I get the error "At least one object must implement IComparable".
>> What does the error mean ?
>> Thanks.
>>
>> Public Class SessionClass
>> Private Quotes As Collection = New Collection
>>     Sub NewQuote(ByVal Message As String)
>>         Dim swError As StreamWriter
>>
>>         Try
>>             Quotes.Add(Message) '--> error here
>>         Catch ex As Exception
>>             swError = New StreamWriter(Application.StartupPath &
>> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
>> vbCrLf, True)
>>             swError.Write(Now & " Session - NewQuote - error = " &
>> ex.Message)
>>             swError.Close()
>>         End Try
>>     End Sub
>
Author
26 Jul 2006 6:11 PM
tommaso.gastaldi
hi :)

It seems you need to read some docs about the object you are using:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamthadd.asp

-tom

fniles ha scritto:

Show quoteHide quote
> Thank you for your reply.
>
> > Can you report what "Message" contains when you get the exception?
> ex.Message = At least one object must implement IComparable
>
> > Also can you report what the 2-nd element of the collection contains
> > at the time of exception?
> I did not catch the value of the 2nd element of the collection when the
> program broke, and this error does not happen all the time.
> May I know why do you need to know the value of the 2nd element of the
> collection ?
>
> > I do not see why not to use a simple arraylist here. The collection
> > uses a keyvalue entry.
> Can you please tell me why simple arraylist will be better than collection ?
> What did you mean by "collection uses a keyvalue entry" ?
>
> Thanks.
>
> <tommaso.gasta***@uniroma1.it> wrote in message
> news:1153933817.292504.65680@m79g2000cwm.googlegroups.com...
> > hi
> > Can you report what "Message" contains when you get the exception?
> >
> > Also can you report what the 2-nd element of the collection contains
> > at the time of exception?
> >
> > -tom
> >
> > PS
> > I do not see why not to use a simple arraylist here. The collection
> > uses a keyvalue entry.
> >
> > fniles ha scritto:
> >
> >> I have a collection inside a class, sometimes when I add to the
> >> collection,
> >> I get the error "At least one object must implement IComparable".
> >> What does the error mean ?
> >> Thanks.
> >>
> >> Public Class SessionClass
> >> Private Quotes As Collection = New Collection
> >>     Sub NewQuote(ByVal Message As String)
> >>         Dim swError As StreamWriter
> >>
> >>         Try
> >>             Quotes.Add(Message) '--> error here
> >>         Catch ex As Exception
> >>             swError = New StreamWriter(Application.StartupPath &
> >> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
> >> vbCrLf, True)
> >>             swError.Write(Now & " Session - NewQuote - error = " &
> >> ex.Message)
> >>             swError.Close()
> >>         End Try
> >>     End Sub
> >
Author
26 Jul 2006 6:27 PM
fniles
Thanks.
They "key" in the "add" method is an optional parameter. I do not use the
key when adding a member to the collection.

Can you please tell me why simple arraylist will be better than collection ?
May I know why do you need to know the value of the 2nd element of the
collection ?

<tommaso.gasta***@uniroma1.it> wrote in message
Show quoteHide quote
news:1153937519.343164.94310@m79g2000cwm.googlegroups.com...
> hi :)
>
> It seems you need to read some docs about the object you are using:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamthadd.asp
>
> -tom
>
> fniles ha scritto:
>
>> Thank you for your reply.
>>
>> > Can you report what "Message" contains when you get the exception?
>> ex.Message = At least one object must implement IComparable
>>
>> > Also can you report what the 2-nd element of the collection contains
>> > at the time of exception?
>> I did not catch the value of the 2nd element of the collection when the
>> program broke, and this error does not happen all the time.
>> May I know why do you need to know the value of the 2nd element of the
>> collection ?
>>
>> > I do not see why not to use a simple arraylist here. The collection
>> > uses a keyvalue entry.
>> Can you please tell me why simple arraylist will be better than
>> collection ?
>> What did you mean by "collection uses a keyvalue entry" ?
>>
>> Thanks.
>>
>> <tommaso.gasta***@uniroma1.it> wrote in message
>> news:1153933817.292504.65680@m79g2000cwm.googlegroups.com...
>> > hi
>> > Can you report what "Message" contains when you get the exception?
>> >
>> > Also can you report what the 2-nd element of the collection contains
>> > at the time of exception?
>> >
>> > -tom
>> >
>> > PS
>> > I do not see why not to use a simple arraylist here. The collection
>> > uses a keyvalue entry.
>> >
>> > fniles ha scritto:
>> >
>> >> I have a collection inside a class, sometimes when I add to the
>> >> collection,
>> >> I get the error "At least one object must implement IComparable".
>> >> What does the error mean ?
>> >> Thanks.
>> >>
>> >> Public Class SessionClass
>> >> Private Quotes As Collection = New Collection
>> >>     Sub NewQuote(ByVal Message As String)
>> >>         Dim swError As StreamWriter
>> >>
>> >>         Try
>> >>             Quotes.Add(Message) '--> error here
>> >>         Catch ex As Exception
>> >>             swError = New StreamWriter(Application.StartupPath &
>> >> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
>> >> vbCrLf, True)
>> >>             swError.Write(Now & " Session - NewQuote - error = " &
>> >> ex.Message)
>> >>             swError.Close()
>> >>         End Try
>> >>     End Sub
>> >
>
Author
26 Jul 2006 6:40 PM
tommaso.gastaldi
I am especially fond of 3 objects which I use often:

arraylist
hashtable
sortedlist

so even if technically the arraylist is a collection, conceptually,
when storing single values,
I prefer the arraylist, also because it is often the case that the
insertion order is meaningful.

In case of exception, if you do not look at what object you actually
stored, it
would be hard to spot the cause of error.

>From the error message it's like you are storing objects different from
strings, which
the compiler does not know how to compare because an IComparable
implemenmtation is missings althought that would not seem possible with
the signature "NewQuote(ByVal Message As String)" but perhaps you
changed something for posting purposes...

-t

fniles ha scritto:

Show quoteHide quote
> Thanks.
> They "key" in the "add" method is an optional parameter. I do not use the
> key when adding a member to the collection.
>
> Can you please tell me why simple arraylist will be better than collection ?
> May I know why do you need to know the value of the 2nd element of the
> collection ?
>
> <tommaso.gasta***@uniroma1.it> wrote in message
> news:1153937519.343164.94310@m79g2000cwm.googlegroups.com...
> > hi :)
> >
> > It seems you need to read some docs about the object you are using:
> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamthadd.asp
> >
> > -tom
> >
> > fniles ha scritto:
> >
> >> Thank you for your reply.
> >>
> >> > Can you report what "Message" contains when you get the exception?
> >> ex.Message = At least one object must implement IComparable
> >>
> >> > Also can you report what the 2-nd element of the collection contains
> >> > at the time of exception?
> >> I did not catch the value of the 2nd element of the collection when the
> >> program broke, and this error does not happen all the time.
> >> May I know why do you need to know the value of the 2nd element of the
> >> collection ?
> >>
> >> > I do not see why not to use a simple arraylist here. The collection
> >> > uses a keyvalue entry.
> >> Can you please tell me why simple arraylist will be better than
> >> collection ?
> >> What did you mean by "collection uses a keyvalue entry" ?
> >>
> >> Thanks.
> >>
> >> <tommaso.gasta***@uniroma1.it> wrote in message
> >> news:1153933817.292504.65680@m79g2000cwm.googlegroups.com...
> >> > hi
> >> > Can you report what "Message" contains when you get the exception?
> >> >
> >> > Also can you report what the 2-nd element of the collection contains
> >> > at the time of exception?
> >> >
> >> > -tom
> >> >
> >> > PS
> >> > I do not see why not to use a simple arraylist here. The collection
> >> > uses a keyvalue entry.
> >> >
> >> > fniles ha scritto:
> >> >
> >> >> I have a collection inside a class, sometimes when I add to the
> >> >> collection,
> >> >> I get the error "At least one object must implement IComparable".
> >> >> What does the error mean ?
> >> >> Thanks.
> >> >>
> >> >> Public Class SessionClass
> >> >> Private Quotes As Collection = New Collection
> >> >>     Sub NewQuote(ByVal Message As String)
> >> >>         Dim swError As StreamWriter
> >> >>
> >> >>         Try
> >> >>             Quotes.Add(Message) '--> error here
> >> >>         Catch ex As Exception
> >> >>             swError = New StreamWriter(Application.StartupPath &
> >> >> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
> >> >> vbCrLf, True)
> >> >>             swError.Write(Now & " Session - NewQuote - error = " &
> >> >> ex.Message)
> >> >>             swError.Close()
> >> >>         End Try
> >> >>     End Sub
> >> >
> >
Author
27 Jul 2006 3:24 PM
fniles
If I need to add and remove items from the arraylist or collection, which
one is faster: arraylist or collection ?

Thank you.

<tommaso.gasta***@uniroma1.it> wrote in message
Show quoteHide quote
news:1153939234.723500.82150@m73g2000cwd.googlegroups.com...
>I am especially fond of 3 objects which I use often:
>
> arraylist
> hashtable
> sortedlist
>
> so even if technically the arraylist is a collection, conceptually,
> when storing single values,
> I prefer the arraylist, also because it is often the case that the
> insertion order is meaningful.
>
> In case of exception, if you do not look at what object you actually
> stored, it
> would be hard to spot the cause of error.
>
>>From the error message it's like you are storing objects different from
> strings, which
> the compiler does not know how to compare because an IComparable
> implemenmtation is missings althought that would not seem possible with
> the signature "NewQuote(ByVal Message As String)" but perhaps you
> changed something for posting purposes...
>
> -t
>
> fniles ha scritto:
>
>> Thanks.
>> They "key" in the "add" method is an optional parameter. I do not use the
>> key when adding a member to the collection.
>>
>> Can you please tell me why simple arraylist will be better than
>> collection ?
>> May I know why do you need to know the value of the 2nd element of the
>> collection ?
>>
>> <tommaso.gasta***@uniroma1.it> wrote in message
>> news:1153937519.343164.94310@m79g2000cwm.googlegroups.com...
>> > hi :)
>> >
>> > It seems you need to read some docs about the object you are using:
>> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamthadd.asp
>> >
>> > -tom
>> >
>> > fniles ha scritto:
>> >
>> >> Thank you for your reply.
>> >>
>> >> > Can you report what "Message" contains when you get the exception?
>> >> ex.Message = At least one object must implement IComparable
>> >>
>> >> > Also can you report what the 2-nd element of the collection contains
>> >> > at the time of exception?
>> >> I did not catch the value of the 2nd element of the collection when
>> >> the
>> >> program broke, and this error does not happen all the time.
>> >> May I know why do you need to know the value of the 2nd element of the
>> >> collection ?
>> >>
>> >> > I do not see why not to use a simple arraylist here. The collection
>> >> > uses a keyvalue entry.
>> >> Can you please tell me why simple arraylist will be better than
>> >> collection ?
>> >> What did you mean by "collection uses a keyvalue entry" ?
>> >>
>> >> Thanks.
>> >>
>> >> <tommaso.gasta***@uniroma1.it> wrote in message
>> >> news:1153933817.292504.65680@m79g2000cwm.googlegroups.com...
>> >> > hi
>> >> > Can you report what "Message" contains when you get the exception?
>> >> >
>> >> > Also can you report what the 2-nd element of the collection contains
>> >> > at the time of exception?
>> >> >
>> >> > -tom
>> >> >
>> >> > PS
>> >> > I do not see why not to use a simple arraylist here. The collection
>> >> > uses a keyvalue entry.
>> >> >
>> >> > fniles ha scritto:
>> >> >
>> >> >> I have a collection inside a class, sometimes when I add to the
>> >> >> collection,
>> >> >> I get the error "At least one object must implement IComparable".
>> >> >> What does the error mean ?
>> >> >> Thanks.
>> >> >>
>> >> >> Public Class SessionClass
>> >> >> Private Quotes As Collection = New Collection
>> >> >>     Sub NewQuote(ByVal Message As String)
>> >> >>         Dim swError As StreamWriter
>> >> >>
>> >> >>         Try
>> >> >>             Quotes.Add(Message) '--> error here
>> >> >>         Catch ex As Exception
>> >> >>             swError = New StreamWriter(Application.StartupPath &
>> >> >> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") &
>> >> >> ".txt" &
>> >> >> vbCrLf, True)
>> >> >>             swError.Write(Now & " Session - NewQuote - error = " &
>> >> >> ex.Message)
>> >> >>             swError.Close()
>> >> >>         End Try
>> >> >>     End Sub
>> >> >
>> >
>
Author
27 Jul 2006 3:48 PM
tommaso.gastaldi
Arraylists are very fast. I have never compared with collection but you
can make some experiment and measure yourself how long they take. Also
for a log, I guess you may need ordered events (Ilist interface).

If you need to make extensive removal take a look at hashtables also or
better a typed collection Dictionary(Of T1, T2)
[System.Collections.Generic.Dictionary]
because removal (not removeat()) isn't O(1)  in arraylist.

If you do some performance experiment please let us know the results.

-t

Show quoteHide quote
> If I need to add and remove items from the arraylist or collection, which
> one is faster: arraylist or collection ?
>
> Thank you.
>
> <tommaso.gasta***@uniroma1.it> wrote in message
> news:1153939234.723500.82150@m73g2000cwd.googlegroups.com...
> >I am especially fond of 3 objects which I use often:
> >
> > arraylist
> > hashtable
> > sortedlist
> >
> > so even if technically the arraylist is a collection, conceptually,
> > when storing single values,
> > I prefer the arraylist, also because it is often the case that the
> > insertion order is meaningful.
> >
> > In case of exception, if you do not look at what object you actually
> > stored, it
> > would be hard to spot the cause of error.
> >
> >>From the error message it's like you are storing objects different from
> > strings, which
> > the compiler does not know how to compare because an IComparable
> > implemenmtation is missings althought that would not seem possible with
> > the signature "NewQuote(ByVal Message As String)" but perhaps you
> > changed something for posting purposes...
> >
> > -t
> >
> > fniles ha scritto:
> >
> >> Thanks.
> >> They "key" in the "add" method is an optional parameter. I do not use the
> >> key when adding a member to the collection.
> >>
> >> Can you please tell me why simple arraylist will be better than
> >> collection ?
> >> May I know why do you need to know the value of the 2nd element of the
> >> collection ?
> >>
> >> <tommaso.gasta***@uniroma1.it> wrote in message
> >> news:1153937519.343164.94310@m79g2000cwm.googlegroups.com...
> >> > hi :)
> >> >
> >> > It seems you need to read some docs about the object you are using:
> >> > http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vamthadd.asp
> >> >
> >> > -tom
> >> >
> >> > fniles ha scritto:
> >> >
> >> >> Thank you for your reply.
> >> >>
> >> >> > Can you report what "Message" contains when you get the exception?
> >> >> ex.Message = At least one object must implement IComparable
> >> >>
> >> >> > Also can you report what the 2-nd element of the collection contains
> >> >> > at the time of exception?
> >> >> I did not catch the value of the 2nd element of the collection when
> >> >> the
> >> >> program broke, and this error does not happen all the time.
> >> >> May I know why do you need to know the value of the 2nd element of the
> >> >> collection ?
> >> >>
> >> >> > I do not see why not to use a simple arraylist here. The collection
> >> >> > uses a keyvalue entry.
> >> >> Can you please tell me why simple arraylist will be better than
> >> >> collection ?
> >> >> What did you mean by "collection uses a keyvalue entry" ?
> >> >>
> >> >> Thanks.
> >> >>
> >> >> <tommaso.gasta***@uniroma1.it> wrote in message
> >> >> news:1153933817.292504.65680@m79g2000cwm.googlegroups.com...
> >> >> > hi
> >> >> > Can you report what "Message" contains when you get the exception?
> >> >> >
> >> >> > Also can you report what the 2-nd element of the collection contains
> >> >> > at the time of exception?
> >> >> >
> >> >> > -tom
> >> >> >
> >> >> > PS
> >> >> > I do not see why not to use a simple arraylist here. The collection
> >> >> > uses a keyvalue entry.
> >> >> >
> >> >> > fniles ha scritto:
> >> >> >
> >> >> >> I have a collection inside a class, sometimes when I add to the
> >> >> >> collection,
> >> >> >> I get the error "At least one object must implement IComparable".
> >> >> >> What does the error mean ?
> >> >> >> Thanks.
> >> >> >>
> >> >> >> Public Class SessionClass
> >> >> >> Private Quotes As Collection = New Collection
> >> >> >>     Sub NewQuote(ByVal Message As String)
> >> >> >>         Dim swError As StreamWriter
> >> >> >>
> >> >> >>         Try
> >> >> >>             Quotes.Add(Message) '--> error here
> >> >> >>         Catch ex As Exception
> >> >> >>             swError = New StreamWriter(Application.StartupPath &
> >> >> >> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") &
> >> >> >> ".txt" &
> >> >> >> vbCrLf, True)
> >> >> >>             swError.Write(Now & " Session - NewQuote - error = " &
> >> >> >> ex.Message)
> >> >> >>             swError.Close()
> >> >> >>         End Try
> >> >> >>     End Sub
> >> >> >
> >> >
> >
Author
26 Jul 2006 5:17 PM
tommaso.gastaldi
hi
Can you report what "Message" contains when you get the exception?

Also can you report what the 2-nd element of the collection contains
at the time of exception?

-tom

PS
I do not see why not to use a simple arraylist here. The collection
uses a keyvalue entry.

fniles ha scritto:

Show quoteHide quote
> I have a collection inside a class, sometimes when I add to the collection,
> I get the error "At least one object must implement IComparable".
> What does the error mean ?
> Thanks.
>
> Public Class SessionClass
> Private Quotes As Collection = New Collection
>     Sub NewQuote(ByVal Message As String)
>         Dim swError As StreamWriter
>
>         Try
>             Quotes.Add(Message) '--> error here
>         Catch ex As Exception
>             swError = New StreamWriter(Application.StartupPath &
> "\AQErrorLog-" & lIndex & "-" & Date.Now.ToString("MMddyy") & ".txt" &
> vbCrLf, True)
>             swError.Write(Now & " Session - NewQuote - error = " &
> ex.Message)
>             swError.Close()
>         End Try
>     End Sub