Tip

Sort NotesOutline

This tip shows you how to sort a NotesOutline object at either the root or first child level. Pass in "" as strParent to sort the root level otherwise pass in the element name to sort under.

It's not very efficient, but since outlines aren't too, too big, it works fine.


Sub OutlineSort ( outline  As NotesOutline, strParent As String) 
     'This routine sorts the outline in alphabetical order 
	
	Dim swap As Integer
	Dim found As Integer
	Dim bFound As Integer
	
	Dim currententry As NotesOutlineEntry
	Dim nextentry As NotesOutlineEntry
	Dim rootentry As NotesOutlineEntry
	
	bFound = False	
	Set rootentry  = outline.GetFirst()
	While Not rootentry Is Nothing And Not bFound
		If rootentry.Label = strParent Then
			bFound = True
		End If
		If Not bFound Then
			Set rootentry = outline.GetNextSibling(rootentry)	
		End If		
	Wend
	
	If strParent <> "" And Not bFound Then
		Exit Sub 'Parent entry not found
	End If
	
top:
	swap = False
	If strParent <> "" Then
		Set currententry  = outline.GetChild(rootentry)
		Set nextentry = outline.GetNextSibling(currententry)
	Else
		Set currententry  = outline.GetFirst()
		Set nextentry = outline.GetNextSibling(currententry)
	End If
	
	
	While Not (currententry  Is Nothing)  And Not (nextentry  Is Nothing) And  swap <> True 
		
		If currententry.Label > nextentry.Label Then
			Call outline.Moveentry(currententry , nextentry, True, False)
			swap = True
		End If
		Set currententry = outline.GetnextSibling(currententry )
		Set nextentry = outline.GetnextSibling(nextentry )		
		
	Wend
	
	If swap Then
		Goto top
	End If
	
	outline.save
	
End Sub

This was first published in August 2001

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.