I have some code that gets a list of all views&folders in a database. The problem is everything is very poorly organized. The list of views shows as almost random, although I assume there is some order...
Is there a way to take the list of all the views that show on the dialog prompt, and then sort the list alphabetically?
Sub Initialize
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim dbSource As NotesDatabase, dbDest As NotesDatabase
Dim source As NotesView, dest As NotesView
Dim vc As NotesViewEntryCollection
Dim docDest As NotesDocument
Dim ve As NotesViewEntry
Dim folders() As String
Dim i As Integer
Dim ret, rez
Set dbSource = s.CurrentDatabase
ForAll v In dbSource.Views
If v.IsFolder Then
i = i + 1
ReDim Preserve folders( i - 1 ) As String
folders( i - 1 ) = v.Name
End If
End ForAll
ret = w.Prompt( PROMPT_OKCANCELLISTMULT, "Folder selection", "Select one or more folders to move.", folders(0), folders )
If IsEmpty( ret ) Then
MessageBox "User canceled", , "Folder not selected"
Exit Sub
Else
rez = w.Prompt( 13, "Database selection", "Choose the database to move the folder to" )
ForAll f In ret
Set source = dbSource.GetView( f )
Set vc = source.AllEntries
Set dbDest = s.GetDatabase( rez(0), rez(1), False )
Call dbDest.EnableFolder( f )
Set ve = vc.GetFirstEntry
Do Until ve Is Nothing
Set docDest = ve.Document.CopyToDatabase( dbDest )
Call docDest.PutInFolder( f )
Set ve = vc.GetNextEntry( ve )
Loop
Call vc.RemoveAllFromFolder( f )
Call source.Remove
End ForAll
End If
End Sub
You can add this subroutine to sort the folders
array before you include it in your prompt method.
Just call ShellSort(folders)
before the line with w.Prompt();
Sub ShellSort( ar( ) As String )
Dim Lower As Integer
Dim Upper As Integer
Dim botMax As Integer
Dim i As Integer
Dim k As Integer
Dim h As Integer
Dim v As String
Lower% = Lbound( ar$( ) )
Upper% = Ubound( ar$( ) )
h% = 1
Do
h% = (3*h%) + 1
Loop Until h% > Upper%-Lower%+1
Do
h% = h% \ 3
botMax% = Lower% + h% - 1
For i% = botMax% + 1 To Upper%
v$ = ar$( i% )
k% = i%
While ar$( k% - h% ) > v$
ar$( k% ) = ar$( k% - h% )
k% = k% - h%
If (k% <= botMax%) Then Goto wOut
Wend
wOut:
If (k% <> i%) Then ar$(k%) = v$
Next
Loop Until h% = 1
End Sub
(source: http://www.dominoexperts.com/articles/Very-fast-sorting-algorithm)