|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
At least one object must implement IComparableI 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 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 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 I did not catch the value of the 2nd element of the collection when the > at the time of exception? 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 Can you please tell me why simple arraylist will be better than collection ?> uses a keyvalue entry. 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 > 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 > > 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 >> > > 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 the compiler does not know how to compare because an IComparablestrings, which 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 > >> > > > 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 >> >> > >> > > 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 > >> >> > > >> > > > 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
How to create multiple threads?
What is an assembly? silly, probably meaninigless question Compiling VB (.NET) files located in different directories Disabling the Form Designer Anyone can help me?£¬How to Convert C# to VB.NET, about Flood Fill Can WinCE & Pocket PC support the "AsyncCallback"? How is it work? How to launch program from CD after vb deployment installed Datagridview - Move Focus to a Particular Cell |
|||||||||||||||||||||||