I see what your saying now I just have to figure out how to get to that
point.  I'm trying sort an Arraylist that contains data from Active
Directory.  I didn't write the classes that create the list.  I'll play
around with it and see what I can come up with.  Any other help you can
offer would be awesome. ;)
 

Thank you, 
Robert Hoenig
Business System Analyst

Johann A. Krause, Inc.
305 W Delavan Drive
Janesville, WI 53547
Phone:     +1 (608) 741-4863
Fax:         +1 (608)  757-7066
E-Mail:    [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]> 
Web:        www.gilmanassembly.com
<blocked::http://www.gilmanassembly.com/>  


 

________________________________

From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of kindawords
Sent: Wednesday, June 15, 2005 11:40 AM
To: [email protected]
Subject: [AspNetAnyQuestionIsOk] Re: ArrayList Sorting


The sorting of a collection is specific to a particular object type.

If your collection holds object type A and you try to sort it using a
sort class that expects object type B, you will get the casting error.

I sent you code that sorts collections holding objects of a type
AnObject.  I am assuming your collection UserGroups holds some other
type of object.  In which case, you have two choices:

1) fill your usergroups collection with AnObject objects and see how
sorting works
2) update whatever type of object you have in the usergroups
collection to implement the IComparable interface and update the
Compare function of AnObjectThatImplementsIComparer to use that type
of object

--- In [email protected], "Hoenig, Robert"
<[EMAIL PROTECTED]> wrote:
> I'm not sure what you mean by UserGroups needs to hold AnObject
> objects??  I'm sorry for being a pain can you elaborate a little more.
> Thanks again.
>  
> 
> Thank you, 
> Robert Hoenig
> Business System Analyst
> 
> Johann A. Krause, Inc.
> 305 W Delavan Drive
> Janesville, WI 53547
> Phone:     +1 (608) 741-4863
> Fax:         +1 (608)  757-7066
> E-Mail:    [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]> 
> Web:        www.gilmanassembly.com
> <blocked::http://www.gilmanassembly.com/>  
> 
> 
>  
> 
> ________________________________
> 
> From: [email protected]
> [mailto:[EMAIL PROTECTED] On Behalf Of kindawords
> Sent: Wednesday, June 15, 2005 11:07 AM
> To: [email protected]
> Subject: [AspNetAnyQuestionIsOk] Re: ArrayList Sorting
> 
> 
> UsersGroups needs to hold AnObject objects.  if it doesn't, you will
> get the error.  What you probably want to do is implement the
> IComparable interface on the class you are storing in the UserGroups
> collection.
> 
> --- In [email protected], "Hoenig, Robert"
> <[EMAIL PROTECTED]> wrote:
> > I did get this fixed.  I had the Implements inside the functions not
> on
> > the declaration line.  Now I'm getting a specified Cast invalid at
pb
> =
> > CType(x, AnObject)
> > 
> > Is there a specific way I have to send to the class?
> >  
> > Dim SortObject As Sort = New Sort
> > 
> > Usergroups.Sort(SortObject)
> > 
> > That is in my call page.  Not sure if that's right ??  
> > 
> >  
> > 
> > Thank you, 
> > Robert Hoenig
> > Business System Analyst
> > 
> > Johann A. Krause, Inc.
> > 305 W Delavan Drive
> > Janesville, WI 53547
> > Phone:     +1 (608) 741-4863
> > Fax:         +1 (608)  757-7066
> > E-Mail:    [EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]> 
> > Web:        www.gilmanassembly.com
> > <blocked::http://www.gilmanassembly.com/>  
> > 
> > 
> >  
> > 
> > ________________________________
> > 
> > From: [email protected]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Hoenig,
> > Robert
> > Sent: Wednesday, June 15, 2005 10:43 AM
> > To: [email protected]
> > Subject: RE: [AspNetAnyQuestionIsOk] Re: ArrayList Sorting
> > 
> > 
> > Your right this is a wee bit confusing but after doing it once it
> should
> > be no biggie :)  Can the classes be on the same .vb page?
> > 
> > sort.vb
> > ------------
> > Public Class AnObjectThatImplementsIComparer
> >     Implements IComparer
> >        Public Function Compare(ByVal x As Object, ByVal y As Object)
> > As Integer Implements System.Collections.IComparer.Compare
> >             Dim pb As AnObject
> >             pb = CType(x, AnObject)
> >             Return pb.CompareTo(y)
> >         End Function
> > End Class
> > 
> > Public Class AnObject
> >     Implements IComparable
> >    Public Score as Double
> >    Public Function CompareTo(ByVal obj As Object) As Integer       
> >      Implements System.IComparable.CompareTo
> >             
> >       Dim pb1 As AnObject = CType(obj, AnObject)
> > 
> >        'This should sort us in descending order
> >         Return pb1.Score.CompareTo(Me.Score)
> >    
> >    End Function
> > End Class
> > ------------
> > 
> > In doing that I'm getting some errors under the Public Class
AnObject.
> > It doesn't either of the Implements
> > 
> > I'm somewhat new to the more advanced programming with VB but really
> > want to learn.  I appreciate your help.
> > 
> > 
> > Thank you, 
> > Robert Hoenig
> > Business System Analyst
> > 
> > Johann A. Krause, Inc.
> > 305 W Delavan Drive
> > Janesville, WI 53547
> > Phone:     +1 (608) 741-4863
> > Fax:         +1 (608)  757-7066
> > E-Mail:    [EMAIL PROTECTED]
> > <mailto:[EMAIL PROTECTED]> 
> > Web:        www.gilmanassembly.com
> > <blocked::http://www.gilmanassembly.com/>  
> > 
> > 
> > 
> > 
> > ________________________________
> > 
> > From: [email protected]
> > [mailto:[EMAIL PROTECTED] On Behalf Of
kindawords
> > Sent: Wednesday, June 15, 2005 10:09 AM
> > To: [email protected]
> > Subject: [AspNetAnyQuestionIsOk] Re: ArrayList Sorting
> > 
> > 
> > This is one of those things that makes sense once you've done it a
few
> > times, but until it clicks it is a wee bit confusing.
> > 
> > You need a class that implements IComparer, which is an interface
with
> > one method, Compare.
> > 
> > Here is an example
> > 
> > Public Class AnObjectThatImplementsIComparer
> >     Implements IComparer
> >        Public Function Compare(ByVal x As Object, ByVal y As Object)
> > As Integer Implements System.Collections.IComparer.Compare
> >             Dim pb As AnObject
> >             pb = CType(x, AnObject)
> >             Return pb.CompareTo(y)
> >         End Function
> > End Class
> > 
> > This compare method is used by the sort call to compare the value of
> > two objects in the collection you are sorting.  As you notice it
> > simply calls the CompareTo method on one of the objects. The object,
> > by the way must implement the IComparable interface.
> > 
> > Public Class AnObject
> >     Implements IComparable
> >    Public Score as Double
> >    Public Function CompareTo(ByVal obj As Object) As Integer       
> >      Implements System.IComparable.CompareTo
> >             
> >       Dim pb1 As AnObject = CType(obj, AnObject)
> > 
> >        'This should sort us in descending order
> >         Return pb1.Score.CompareTo(Me.Score)
> >    
> >    End Function
> > End Class
> > 
> > As you notice this method calls CompareTo as well, and this simply
> > compares the .Score properties on both objects.
> > 
> > So when you call .Sort on your collection
> > Dim SortObject as AnObjectThatImplementsIComparer = new
> > AnObjectThatImplementsIComparer
> > 
> > ACollection.Sort(SortObject)
> > 
> > your collection gets sorted.
> > 
> > --- In [email protected], "Hoenig, Robert"
> > <[EMAIL PROTECTED]> wrote:
> > > Can someone please help me with sorting an array list.  I added
> > > arrlist.sort() and now it wants the ICompare.  How do I implement
> the
> > > ICompare class??  Some simple sample code would be greatly
> > appreciated.
> > >  
> > > Thank you, 
> > > Robert Hoenig
> > > Business System Analyst
> > > 
> > > Johann A. Krause, Inc.
> > > 305 W Delavan Drive
> > > Janesville, WI 53547
> > > Phone:     +1 (608) 741-4863
> > > Fax:         +1 (608)  757-7066
> > > E-Mail:    [EMAIL PROTECTED]  
> > > <mailto:[EMAIL PROTECTED]> 
> > > Web:        www.gilmanassembly.com
> > > <blocked::http://www.gilmanassembly.com/> 
> > > 
> > > 
> > > This email has been scanned by the Gilman Engineering &
> > Manufacturing, LLC
> > >  Email Security System.
> > > 
> > > 
> > > [Non-text portions of this message have been removed]
> > 
> > 
> > 
> > 
> > ________________________________
> > 
> > Yahoo! Groups Links
> > 
> > 
> > *      To visit your group on the web, go to:
> >       http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
> >         
> > *      To unsubscribe from this group, send an email to:
> >       [EMAIL PROTECTED]
> >
>
<mailto:[EMAIL PROTECTED]
> > cribe> 
> >         
> > *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > Service <http://docs.yahoo.com/info/terms/> . 
> > 
> > 
> > 
> >
______________________________________________________________________
> > This email has been scanned by the MessageLabs Email Security
System.
> > For more information please visit http://www.messagelabs.com/email 
> >
______________________________________________________________________
> > 
> > 
> > 
> > This email has been scanned by the Gilman Engineering &
Manufacturing,
> > LLC
> > Email Security System.
> > 
> > 
> > [Non-text portions of this message have been removed]
> > 
> > 
> > 
> > ________________________________
> > 
> > Yahoo! Groups Links
> > 
> > 
> > *      To visit your group on the web, go to:
> >       http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
> >         
> > *      To unsubscribe from this group, send an email to:
> >       [EMAIL PROTECTED]
> >
>
<mailto:[EMAIL PROTECTED]
> > cribe> 
> >         
> > *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > Service <http://docs.yahoo.com/info/terms/> . 
> > 
> > 
> > 
> >
______________________________________________________________________
> > This email has been scanned by the MessageLabs Email Security
System.
> > For more information please visit http://www.messagelabs.com/email 
> >
______________________________________________________________________
> > 
> > 
> > 
> > This email has been scanned by the Gilman Engineering &
> Manufacturing, LLC
> >  Email Security System.
> > 
> > 
> > [Non-text portions of this message have been removed]
> 
> 
> 
> 
> ________________________________
> 
> Yahoo! Groups Links
> 
> 
> *      To visit your group on the web, go to:
>       http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
>         
> *      To unsubscribe from this group, send an email to:
>       [EMAIL PROTECTED]
>
<mailto:[EMAIL PROTECTED]
> cribe> 
>         
> *      Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/> . 
> 
> 
> 
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email 
> ______________________________________________________________________
> 
> 
> 
> This email has been scanned by the Gilman Engineering &
Manufacturing, LLC
>  Email Security System.
> 
> 
> [Non-text portions of this message have been removed]





________________________________

Yahoo! Groups Links


*       To visit your group on the web, go to:
        http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
          
*       To unsubscribe from this group, send an email to:
        [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]
cribe> 
          
*       Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service <http://docs.yahoo.com/info/terms/> . 



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________



This email has been scanned by the Gilman Engineering & Manufacturing, LLC
 Email Security System.


[Non-text portions of this message have been removed]



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to