473,503 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

At least one object must implement IComparable

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
Jul 26 '06 #1
8 14731
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
Jul 26 '06 #2
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
Jul 26 '06 #3
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.

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.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

Jul 26 '06 #4
hi :)

It seems you need to read some docs about the object you are using:
http://msdn.microsoft.com/library/de...l/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.

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.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
Jul 26 '06 #5
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 ?

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
hi :)

It seems you need to read some docs about the object you are using:
http://msdn.microsoft.com/library/de...l/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.

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegr oups.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

Jul 26 '06 #6
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 ?

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
hi :)

It seems you need to read some docs about the object you are using:
http://msdn.microsoft.com/library/de...l/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.

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.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
Jul 26 '06 #7
If I need to add and remove items from the arraylist or collection, which
one is faster: arraylist or collection ?

Thank you.

<to**************@uniroma1.itwrote in message
news:11*********************@m73g2000cwd.googlegro ups.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 ?

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegr oups.com...
hi :)

It seems you need to read some docs about the object you are using:
http://msdn.microsoft.com/library/de...l/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.

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegr oups.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


Jul 27 '06 #8
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
If I need to add and remove items from the arraylist or collection, which
one is faster: arraylist or collection ?

Thank you.

<to**************@uniroma1.itwrote in message
news:11*********************@m73g2000cwd.googlegro ups.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 ?

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
hi :)

It seems you need to read some docs about the object you are using:
http://msdn.microsoft.com/library/de...l/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.

<to**************@uniroma1.itwrote in message
news:11*********************@m79g2000cwm.googlegro ups.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
Jul 27 '06 #9

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

Similar topics

3
1658
by: Steve Teeples | last post by:
Can someone explain how to cast an object to a specific type during runtime? // This line of code tells me the objects type. System.Type type = System.Type.GetType("string of the type"); //...
8
1509
by: ECathell | last post by:
I have a class called products. In my maintenance application I am instantiating two versions of this class. mProduct is used in all transactions and changes mProduct_original is loaded at the...
8
1871
by: Alexander Walker | last post by:
Hello I am using a Dictionary to store some queues which store instances of a class that I have written I would like to be able to determine whether a particular queue already contains an...
6
1817
by: AAJ | last post by:
Hi all I have some objects that I add to an ArrayList. Each object is from the same class and has methods etc. Each can be identified by a unique property, in this case PK e.g. PK =1 for...
2
1360
by: preport | last post by:
Hopefully someone can clarify some of this for me. I am confused on what classes I should implement if I want to utilize the List<>.BinarySearch() and Sort() My class currently looks like: ...
4
1576
by: FacultasNetDeveloper | last post by:
I am extending FileSystemInfo class so that I can Implement Icomparable. My custom class looks like: Class FSFileSystemInfo Inherits FileSystemInfo : Implements Icomparable Function...
3
1444
by: Ron M. Newman | last post by:
Hi, Is there a quick way to know if a given object implements IComparable? (without casting or anything like that). Something that uses reflection? Thanks -Ron
10
2748
by: Sjaakie | last post by:
Hi, I'm, what it turns out to be, fooling around with 3-tier design. At several websites people get really enthusiastic about using custom dataobjects instead of datasets/-tables. While trying to...
14
2512
by: serge calderara | last post by:
Dear all, What is the proper way to check if two object are equal ? I do not mean equal on Object type only but also object value's thnaks for help regards serge
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7348
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.