On 01/24/01 09:15:41 you wrote:
>
>
>Does anyone know of an existing algorithm to sort a RoseClassCollection
>alphabetically by class name?

'**********************************************************
' Subrountine: SortClassCollection
'          Author: Tony Lew, Rational Technical Support
'        Date: January 24, 2001
'
'      Input:  
'              cc:  classCollection
'            CASE_SENSITIVE: Boolean
'      Output:
'              cc:  classCollection sorted alphabetically
'
'      Algorithm: Since it is not possible to rearrange the
'                 elements of a collection in Rosescript,
'                 a new sorted collection is created which
'                 then replaces the old collection.
'                  Note:  ArraySort assumes that capital letters sort
'                 before small letters.
'
'
'************************************************************
Function FindClassNoCase(Nomine As String, cc As classCollection) As class
Dim i As Integer
For i = 1 To cc.count
  If UCase$(Nomine) = UCase$(cc.getat(i).name) Then
     Set FindClassNoCase = cc.getat(i)
         Exit Function
  End If
Next i
Set FindClassNoCase = Nothing 
End Function

Sub SortClassCollection(cc As ClassCollection, CASE_SENSITIVE As Boolean)
Dim zot() As String
ReDim zot(1 To cc.count)
Dim i As Integer
For i = 1 To cc.count
  If CASE_SENSITIVE Then
     zot(i) = cc.getat(i).name
  Else 
     zot(i) = UCase$(cc.getat(i).name)
  End If
Next i
ArraySort zot

Dim sorted As New ClassCollection
Dim c As class
Dim nomine As String
For i = 1 To cc.count
  nomine = zot(i)
  If CASE_SENSITIVE Then
      Set c = cc.getFirst(nomine)
  Else
      Set c = FindClassNoCase(nomine,cc)
  End If
  sorted.add c  
Next i

Set cc = sorted


End Sub

Sub Main

Dim cc As ClassCollection
Set cc = Roseapp.currentmodel.getallClasses
SortclassCollection cc, FALSE

viewport.open
viewport.clear

For i = 1 To cc.count
  Print cc.getat(i).name
Next i

        
End Sub



>Thanks,
>Jeff Engler [EMAIL PROTECTED]
>
>************************************************************************
>* Rose Forum is a public venue for ideas and discussions.
>* For technical support, visit http://www.rational.com/support
>*
>* Admin.Subscription Requests: [EMAIL PROTECTED]
>* Archive of messages: 
>http://www.rational.com/products/rose/usergroups/rose_forum.jtmpl
>* Other Requests: [EMAIL PROTECTED]
>*
>* To unsubscribe from the list, please send email
>*
>* To: [EMAIL PROTECTED]
>* Subject:<BLANK>
>* Body: unsubscribe rose_forum
>*
>*************************************************************************
>
>



************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Admin.Subscription Requests: [EMAIL PROTECTED]
* Archive of messages: 
http://www.rational.com/products/rose/usergroups/rose_forum.jtmpl
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*
* To: [EMAIL PROTECTED]
* Subject:<BLANK>
* Body: unsubscribe rose_forum
*
*************************************************************************

Reply via email to