/
miscdelay.bas
327 lines (244 loc) · 8.44 KB
/
miscdelay.bas
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
Attribute VB_Name = "CodeMiscDelay"
' (c) Copyright 1995-2024 by John J. Donovan
Option Explicit
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sub MiscTimer(timeinterval As Single)
' Waits a specified number of seconds before returning (fractional second precision)
' Usage: Call MiscTimer(secondsdelay!)
ierror = False
On Error GoTo MiscTimerError
Dim startsec As Single, elapsedsec As Single
If timeinterval! <= 0# Then Exit Sub
If timeinterval! > SECPERDAY# Then GoTo MiscTimerBadInterval
Screen.MousePointer = vbHourglass
icancelauto = False
startsec! = Timer() ' set start seconds
Do While elapsedsec! < startsec! + timeinterval!
elapsedsec! = Timer()
If elapsedsec! < startsec! Then startsec! = startsec! - SECPERDAY# ' in case timer goes through midnight
DoEvents ' yield to other processes
Sleep (timeinterval! * MSECPERSEC# / 10#) ' yield to other apps
' Check for cancel
If icancelauto Then
Screen.MousePointer = vbDefault
ierror = True
Exit Sub
End If
Loop
Screen.MousePointer = vbDefault
Exit Sub
' Errors
MiscTimerError:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "MiscTimer"
ierror = True
Exit Sub
MiscTimerBadInterval:
msg$ = "Timer interval exceeds number of seconds in a day"
MsgBox msg$, vbOKOnly + vbExclamation, "MiscTimer"
ierror = True
Exit Sub
End Sub
Sub MiscTimer2(timeinterval As Single)
' Waits a specified number of seconds before returning (fractional second precision)
' Usage: Call MiscTimer2(secondsdelay!) (no hourglass)
ierror = False
On Error GoTo MiscTimer2Error
Dim startsec As Single, elapsedsec As Single
If timeinterval! <= 0# Then Exit Sub
If timeinterval! > SECPERDAY# Then GoTo MiscTimer2BadInterval
icancelauto = False
startsec! = Timer() ' set start seconds
Do While elapsedsec! < startsec! + timeinterval!
elapsedsec! = Timer()
If elapsedsec! < startsec! Then startsec! = startsec! - SECPERDAY# ' in case timer goes through midnight
DoEvents ' yield to other processes
Sleep (timeinterval! * MSECPERSEC# / 10#) ' yield to other apps
' Check for cancel
If icancelauto Then
ierror = True
Exit Sub
End If
Loop
Exit Sub
' Errors
MiscTimer2Error:
MsgBox Error$, vbOKOnly + vbCritical, "MiscTimer2"
ierror = True
Exit Sub
MiscTimer2BadInterval:
msg$ = "Timer interval exceeds number of seconds in a day"
MsgBox msg$, vbOKOnly + vbExclamation, "MiscTimer2"
ierror = True
Exit Sub
End Sub
Sub MiscDelay(timeinterval As Double, previoustime As Double)
' Waits a specified number of seconds before returning
' Usage: Call MiscDelay(CDbl(secondsdelay!), Now)
ierror = False
On Error GoTo MiscDelayError
If timeinterval# <= 0# Then Exit Sub
' Loop until current date/time exceeds specified interval in seconds
Screen.MousePointer = vbHourglass
Do
If Now > timeinterval# / SECPERDAY# + previoustime# Then Exit Do
DoEvents
' Check for cancel
If icancelauto Then
Screen.MousePointer = vbDefault
ierror = True
Exit Sub
End If
Loop
Screen.MousePointer = vbDefault
Exit Sub
' Errors
MiscDelayError:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "MiscDelay"
ierror = True
Exit Sub
End Sub
Sub MiscDelay2(nloop As Long)
' Waits a specified number of loops before returning
' Usage: Call MiscDelay2(1000)
ierror = False
On Error GoTo MiscDelay2Error
Dim n As Long
' Loop
Screen.MousePointer = vbHourglass
For n = 1 To nloop&
DoEvents
' Check for cancel
If icancelauto Then
Screen.MousePointer = vbDefault
ierror = True
Exit Sub
End If
Next n&
Screen.MousePointer = vbDefault
Exit Sub
' Errors
MiscDelay2Error:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "MiscDelay2"
ierror = True
Exit Sub
End Sub
Sub MiscDelay3(tStatus As StatusBar, waitingmessage As String, timeinterval As Double, previoustime As Double)
' Waits a specified number of seconds before returning (updates status text)
' Usage: Call MiscDelay3(tStatus as StatusBar, waitingmessage$, CDbl(secondsdelay!), Now)
ierror = False
On Error GoTo MiscDelay3Error
Dim atemp As Double
If timeinterval# <= 0# Then Exit Sub
' Loop until current date/time exceeds specified interval in seconds
Screen.MousePointer = vbHourglass
Do
If Now > timeinterval# / SECPERDAY# + previoustime# Then Exit Do
DoEvents
' Update caption
atemp# = (timeinterval# / SECPERDAY# + previoustime#) - Now
tStatus.Panels(1).Text = Format$(atemp# * SECPERDAY#, f81$) & " seconds remaining for " & waitingmessage$
DoEvents ' yield to this app
Sleep (100) ' yield to other apps
' Check for cancel
If icancelauto Then
Screen.MousePointer = vbDefault
ierror = True
Exit Sub
End If
Loop
tStatus.Panels(1).Text = vbNullString
Screen.MousePointer = vbDefault
Exit Sub
' Errors
MiscDelay3Error:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "MiscDelay3"
ierror = True
Exit Sub
End Sub
Sub MiscDelay4(timeinterval As Double, previoustime As Double)
' Waits a specified number of seconds before returning
' (no doevents- program will "freeze" during the delay)
' Usage: Call MiscDelay4(CDbl(secondsdelay!), Now)
ierror = False
On Error GoTo MiscDelay4Error
If timeinterval# <= 0# Then Exit Sub
' Loop until current date/time exceeds specified interval in seconds
Screen.MousePointer = vbHourglass
Do
If Now > timeinterval# / SECPERDAY# + previoustime# Then Exit Do
Loop
Screen.MousePointer = vbDefault
Exit Sub
' Errors
MiscDelay4Error:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "MiscDelay4"
ierror = True
Exit Sub
End Sub
Sub MiscDelay5(timeinterval As Double, previoustime As Double)
' Waits a specified number of seconds before returning (without hourglass cursor)
' Usage: Call MiscDelay5(CDbl(secondsdelay!), Now)
ierror = False
On Error GoTo MiscDelay5Error
If timeinterval# <= 0# Then Exit Sub
' Loop until current date/time exceeds specified interval in seconds
Do
If Now > timeinterval# / SECPERDAY# + previoustime# Then Exit Do
DoEvents
' Check for cancel
If icancelauto Then
ierror = True
Exit Sub
End If
Loop
Exit Sub
' Errors
MiscDelay5Error:
MsgBox Error$, vbOKOnly + vbCritical, "MiscDelay5"
ierror = True
Exit Sub
End Sub
Sub MiscDelay6(tStatus As StatusBar, waitingmessage As String, timeinterval As Double, previoustime As Double)
' Waits a specified number of seconds before returning (updates status text without DoEvents)
' Usage: Call MiscDelay6(tStatus as StatusBar, waitingmessage$, CDbl(secondsdelay!), Now)
ierror = False
On Error GoTo MiscDelay6Error
Dim atemp As Double
If timeinterval# <= 0# Then Exit Sub
' Loop until current date/time exceeds specified interval in seconds
Screen.MousePointer = vbHourglass
Do
If Now > timeinterval# / SECPERDAY# + previoustime# Then Exit Do
' Update caption
atemp# = (timeinterval# / SECPERDAY# + previoustime#) - Now
tStatus.Panels(1).Text = Format$(atemp# * SECPERDAY#, f81$) & " seconds remaining for " & waitingmessage$
Sleep (100) ' yield to other apps
' Check for cancel
If icancelauto Then
Screen.MousePointer = vbDefault
ierror = True
Exit Sub
End If
Loop
tStatus.Panels(1).Text = vbNullString
Screen.MousePointer = vbDefault
Exit Sub
' Errors
MiscDelay6Error:
Screen.MousePointer = vbDefault
MsgBox Error$, vbOKOnly + vbCritical, "MiscDelay6"
ierror = True
Exit Sub
End Sub