At least one object must implement IComparable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fniles

    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(Mess age) '--error here
    Catch ex As Exception
    swError = New StreamWriter(Ap plication.Start upPath &
    "\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
    vbCrLf, True)
    swError.Write(N ow & " Session - NewQuote - error = " &
    ex.Message)
    swError.Close()
    End Try
    End Sub


  • tommaso.gastaldi@uniroma1.it

    #2
    Re: At least one object must implement IComparable

    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(Mess age) '--error here
    Catch ex As Exception
    swError = New StreamWriter(Ap plication.Start upPath &
    "\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
    vbCrLf, True)
    swError.Write(N ow & " Session - NewQuote - error = " &
    ex.Message)
    swError.Close()
    End Try
    End Sub

    Comment

    • tommaso.gastaldi@uniroma1.it

      #3
      Re: At least one object must implement IComparable

      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(Mess age) '--error here
      Catch ex As Exception
      swError = New StreamWriter(Ap plication.Start upPath &
      "\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
      vbCrLf, True)
      swError.Write(N ow & " Session - NewQuote - error = " &
      ex.Message)
      swError.Close()
      End Try
      End Sub

      Comment

      • fniles

        #4
        Re: At least one object must implement IComparable

        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.gastal di@uniroma1.itw rote in message
        news:1153933817 .292504.65680@m 79g2000cwm.goog legroups.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(Mess age) '--error here
        > Catch ex As Exception
        > swError = New StreamWriter(Ap plication.Start upPath &
        >"\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
        >vbCrLf, True)
        > swError.Write(N ow & " Session - NewQuote - error = " &
        >ex.Message)
        > swError.Close()
        > End Try
        > End Sub
        >

        Comment

        • tommaso.gastaldi@uniroma1.it

          #5
          Re: At least one object must implement IComparable

          hi :)

          It seems you need to read some docs about the object you are using:


          -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.gastal di@uniroma1.itw rote in message
          news:1153933817 .292504.65680@m 79g2000cwm.goog legroups.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(Mess age) '--error here
          Catch ex As Exception
          swError = New StreamWriter(Ap plication.Start upPath &
          "\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
          vbCrLf, True)
          swError.Write(N ow & " Session - NewQuote - error = " &
          ex.Message)
          swError.Close()
          End Try
          End Sub

          Comment

          • fniles

            #6
            Re: At least one object must implement IComparable

            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.gastal di@uniroma1.itw rote in message
            news:1153937519 .343164.94310@m 79g2000cwm.goog legroups.com...
            hi :)
            >
            It seems you need to read some docs about the object you are using:

            >
            -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 ldi@uniroma1.it wrote in message
            >news:115393381 7.292504.65680@ m79g2000cwm.goo glegroups.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(Mess age) '--error here
            > Catch ex As Exception
            > swError = New StreamWriter(Ap plication.Start upPath &
            >"\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
            >vbCrLf, True)
            > swError.Write(N ow & " Session - NewQuote - error = " &
            >ex.Message)
            > swError.Close()
            > End Try
            > End Sub
            >
            >

            Comment

            • tommaso.gastaldi@uniroma1.it

              #7
              Re: At least one object must implement IComparable

              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(B yVal 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.gastal di@uniroma1.itw rote in message
              news:1153937519 .343164.94310@m 79g2000cwm.goog legroups.com...
              hi :)

              It seems you need to read some docs about the object you are using:


              -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.gastal di@uniroma1.itw rote in message
              news:1153933817 .292504.65680@m 79g2000cwm.goog legroups.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(Mess age) '--error here
              Catch ex As Exception
              swError = New StreamWriter(Ap plication.Start upPath &
              "\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") & ".txt" &
              vbCrLf, True)
              swError.Write(N ow & " Session - NewQuote - error = " &
              ex.Message)
              swError.Close()
              End Try
              End Sub

              Comment

              • fniles

                #8
                Re: At least one object must implement IComparable

                If I need to add and remove items from the arraylist or collection, which
                one is faster: arraylist or collection ?

                Thank you.

                <tommaso.gastal di@uniroma1.itw rote in message
                news:1153939234 .723500.82150@m 73g2000cwd.goog legroups.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(B yVal 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 ldi@uniroma1.it wrote in message
                >news:115393751 9.343164.94310@ m79g2000cwm.goo glegroups.com.. .
                hi :)
                >
                It seems you need to read some docs about the object you are using:

                >
                -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 ldi@uniroma1.it wrote in message
                >news:115393381 7.292504.65680@ m79g2000cwm.goo glegroups.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(Mess age) '--error here
                > Catch ex As Exception
                > swError = New StreamWriter(Ap plication.Start upPath &
                >"\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") &
                >".txt" &
                >vbCrLf, True)
                > swError.Write(N ow & " Session - NewQuote - error = " &
                >ex.Message)
                > swError.Close()
                > End Try
                > End Sub
                >
                >
                >

                Comment

                • tommaso.gastaldi@uniroma1.it

                  #9
                  Re: At least one object must implement IComparable

                  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.Collecti ons.Generic.Dic tionary]
                  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.
                  >
                  <tommaso.gastal di@uniroma1.itw rote in message
                  news:1153939234 .723500.82150@m 73g2000cwd.goog legroups.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(B yVal 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.gastal di@uniroma1.itw rote in message
                  news:1153937519 .343164.94310@m 79g2000cwm.goog legroups.com...
                  hi :)

                  It seems you need to read some docs about the object you are using:


                  -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.gastal di@uniroma1.itw rote in message
                  news:1153933817 .292504.65680@m 79g2000cwm.goog legroups.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(Mess age) '--error here
                  Catch ex As Exception
                  swError = New StreamWriter(Ap plication.Start upPath &
                  "\AQErrorLo g-" & lIndex & "-" & Date.Now.ToStri ng("MMddyy") &
                  ".txt" &
                  vbCrLf, True)
                  swError.Write(N ow & " Session - NewQuote - error = " &
                  ex.Message)
                  swError.Close()
                  End Try
                  End Sub

                  Comment

                  Working...