I put together this utility agent for testing and running other agents on the current DB's server. The agent gets the list of agents in the db, sorts them by name, presents the list of alphabetically sorted agents, runs the selected agent on the server, and then provides a message box letting you know if the agent ran successfully or not. I did not create the quicksort routine and, unfortunately, I can't find the name of the person responsible for creating it.
Code
Declarations
Dim session As NotesSession
Dim ws As NotesUIWorkspace
Dim db As NotesDatabase
Dim agenttorun As NotesAgent
Dim values() As String
Sub Initialize
Set session = New NotesSession
Set ws = New NotesUIWorkspace
Set db = session.CurrentDatabase
prompttype% = PROMPT_OKCANCELLIST
title$ = "Agent List"
prompt$ = "Pick an Agent"
defaultvalue$ = ""
count% = Ubound(db.Agents)
Redim values(count%) As String
Forall agents In db.Agents
values(agentcount%) = agents.Name
agentcount% = agentcount% + 1
End Forall
Call quicksort(Lbound(values),Ubound(values),values)
selectedagent = ws.Prompt( prompttype%,
title$, prompt$, defaultvalue$,values)
If Cstr(selectedagent) <> "" Then
Set agenttorun = db.GetAgent(Cstr(selectedagent))
If agenttorun.RunOnServer = 0 Then
Messagebox "Agent ran",, "Success"
Else
Messagebox "Agent did not run",, "Failure"
End If
End If
End Sub
Sub quicksort (l As Integer,r As Integer, arrayelts As Variant)
Dim m As Variant
Dim i As Integer
Dim t As Variant
Dim j As Integer
If r > l Then 'If there's nothing to sort, jump out
m = arrayelts(l) 'Initialize boundaries, nominate a
value to sort
j = r
i = l
While (i < j) 'Repeat until i and j "meet in the middle"
While (arrayelts(i) <= m And i < r) 'Push in the boundaries
while data is sorted
i = i + 1
Wend
While (arrayelts(j) > m)
j = j - 1
Wend
If i < j Then 'If there is data between i and j something
is out of order - swap it
t = arrayelts(i)
arrayelts(i) = arrayelts(j)
arrayelts(j) = t
End If
Wend
t = arrayelts(l) 'Swap the nominated and bottom values -
why we came here
arrayelts(l) = arrayelts(j)
arrayelts(j) = t
Call quicksort (l, j - 1, arrayelts) 'Recurse and sort data either
side of upper bound
Call quicksort ((j + 1), r, arrayelts)
End If
End Sub