-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneric_agent.lss
223 lines (192 loc) · 5.8 KB
/
Generic_agent.lss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
Option Public
Option Declare
Dim SortedArray As Variant
Sub Initialize
' General purpose agent skeleton, note that the front end stuff won't work in back-end agent.
On Error Goto errorhdlr
Dim sess As New notessession
Dim ws As New notesuiworkspace
Dim db As notesdatabase
' Dim db2 As New notesdatabase("server","pathname")
Dim view As notesview
Dim view2 As notesview
Dim lookupview As notesview
Dim dc As notesdocumentcollection
Dim doc As notesdocument
Dim doc2 As notesdocument
Dim lookupdoc As notesdocument
Dim cnt As Integer
Dim dccnt As Integer
Dim iconstyle As Integer
Dim retval As Integer
Dim ptype As Integer
Dim filenum As Integer
Dim message As String
Dim title As String
Dim default As String
Dim retstr As String
Dim parray() As String
Dim key As String
Dim retvar As Variant
Dim filename As String
'__________________________________________________________________________
Print "Agent starts at " & Time$
Set db = sess.currentdatabase
Print "Agent ends at " & Time$
Exit Sub
'__________________________________________________________________________
processviewsub:
Set view = db.getview("Viewname/alias")
Set doc = view.getfirstdocument
cnt = 1
Do Until doc Is Nothing
Set doc = view.getnextdocument(doc)
cnt = cnt + 1
Loop
Return
processdcsub:
Set dc = db.unprocesseddocuments
Set doc = dc.getfirstdocument
dccnt = 1
Do Until doc Is Nothing
Set doc = dc.getnextdocument(doc)
dccnt = dccnt + 1
Loop
Return
lookupviewsub:
' Set view2 = db.getview("Viewname/alias") same DB
' Set view2 = db2.getview("Viewname/alias") different DB
Set doc2 = view2.getdocumentbykey(key,True)
Return
lookupnsfsub:
Dim lookupdb As New notesdatabase(db.server,"lookup.nsf")
Set lookupview = lookupdb.getview("A1")
Set lookupdoc = lookupview.getdocumentbykey("*** KEY ***")
Return
processfilesub:
filenum = Freefile()
filename = "Insert filename"
Open filename For Output As fileNum
Write #filenum,"Values"
Close fileNum
Return
msgboxoksub:
' No return value (OK only)
' iconstyle 16 = Stop, iconstyle 48 = Exclamation, iconstyle 64 = Information
Messagebox message, iconstyle, title
Return
msgboxretsub:
' Return values (into retval)
' 1 OK IDOK
' 2 Cancel IDCANCEL
' 3 Abort IDABORT
' 4 Retry IDRETRY
' 5 Ignore IDIGNORE
' 6 Yes IDYES
' 7 No IDNO
' OK/Cancel : iconstyle 17 = Stop, iconstyle 33 = Question, iconstyle 49 = Exclamation, iconstyle 65 = Information
' Yes/No/Cancel : iconstyle 19 = Stop, iconstyle 35 = Question, iconstyle 51 = Exclamation, iconstyle 67 = Information
' Yes/No : iconstyle 20 = Stop, iconstyle 36 = Question, iconstyle 52 = Exclamation, iconstyle 68 = Information
retval = Messagebox (message, iconstyle, title)
Return
inputboxsub:
retstr = Inputbox$(message, title, default)
Return
wspromptoksub:
' ptype can be
' PROMPT_OK, PROMPT_YESNO, PROMPT_YESNOCANCEL
retvar = ws.Prompt( ptype, title, message)
Return
wspromptretsub:
' ptype can be
' PROMPT_OKCANCELEDIT, PROMPT_OKCANCELLIST, PROMPT_OKCANCELCOMBO
' PROMPT_OKCANCELEDITCOMBO, PROMPT_OKCANCELLISTMULT, PROMPT_PASSWORD
retvar = ws.Prompt( ptype, title, message, default , parray )
Return
quicksortsub:
Call QuickSort("variant containing array")
' RETURNED SORTED ARRAY IS IN THE GLOBAL SortedArray
Return
errorhdlr:
Print "Error " & Str(Err) & " : " & Error$ & " at " & Cstr(Erl) & " in " & Lsi_info(2) & " " & Lsi_info(12)
Resume Next
End Sub
Sub DoInsertSort ( sA() As String, Byval bottom As Long, Byval top As Long )
Dim i As Long
Dim x As Long
Dim v As String
Dim Found As Integer
For i = bottom+1 To top
x = i
v = sA (i )
Do While (sA(x-1) > v) ' SORT ASCENDING
' Do While (sA(x-1) < v) ' SORT DESCENDING
sA ( x ) = sA ( x-1 )
x = x - 1
If x=0 Then
Exit Do
End If
Loop
sA (x) = v
Next
End Sub
Public Function QuickSort(sArray As Variant)
Dim sA() As String
Dim j As Long
Dim bottom As Long
Dim top As Long
bottom = Lbound ( sArray )
top = Ubound ( sArray )
Redim sA( bottom To top ) As String
For j = bottom To top
sA ( j ) = sArray ( j )
Next
' DoQS does a QuickSort if the Sublist is longer than 10 elements
' Thus, when DoQS finishes, all elements are within 10 spots of their correct location.
' For lists that are close to being in order, an Insertion Sort is much faster than a QuickSort, so we
' run through the whole thing once doing an Insertion Sort to finish tidying up the order.
Call DoQS( sA, bottom, top )
Call DoInsertSort ( sA, bottom, top )
SortedArray = sA
End Function
Sub DoQS( sA() As String, bottom As Long, top As Long )
' Called by QuickSort
' Uses Public variable sA (array of string)
Dim length As Long
Dim i As Long
Dim j As Long
Dim Pivot As Long
Dim PivotValue As String
Dim t As String
Dim LastSmall As Long
length = top - bottom + 1
' Only do the QuickSort if the sublist is at least 10 items long
If length > 10 Then
' Pivot is chosen approx. halfway through sublist.
' This gives us best speed if list is almost sorted already, and is no worse than any
' other choice if the list is in random order.
Pivot = bottom + (length \ 2)
' Move PivotValue out of the way
PivotValue = sA( Pivot )
sA ( Pivot ) = sA ( bottom )
sA ( bottom ) = PivotValue
' LastSmall is the location of the last value smaller than PivotValue
LastSmall = bottom
For i = bottom + 1 To top
If sA ( i ) < PivotValue Then
LastSmall = LastSmall + 1
t = sA ( i )
sA ( i ) = sA ( LastSmall )
sA ( LastSmall ) = t
End If
Next
' Move the PivotValue back
t = sA ( LastSmall )
sA ( LastSmall ) = sA ( bottom )
sA ( bottom ) = t
Pivot = LastSmall
' Now sort each side
Call DoQS ( sA, bottom, Pivot - 1 )
Call DoQS ( sA, Pivot + 1, top )
End If
End Sub