nss: upgrade to release 3.73
[LibreOffice.git] / wizards / source / access2base / Python.xba
blob94a44215995dc6a9e225e85c48ba5d2e025bd635
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Python" script:language="StarBasic">
4 REM =======================================================================================================================
5 REM === The Access2Base library is a part of the LibreOffice project. ===
6 REM === Full documentation is available on http://www.access2base.com ===
7 REM =======================================================================================================================
9 Option Compatible
10 Option Explicit
12 REM -----------------------------------------------------------------------------------------------------------------------
13 Public Sub DebugPrint(ParamArray pvArgs() As Variant)
15 &apos;Print arguments unconditionally in console
16 &apos;Arguments are separated by a TAB (simulated by spaces)
17 &apos;Some pvArgs might be missing: a TAB is still generated
19 Dim vVarTypes() As Variant, i As Integer
20 Const cstTab = 5
21 On Local Error Goto Exit_Sub &apos; Never interrupt processing
22 Utils._SetCalledSub(&quot;DebugPrint&quot;)
23 vVarTypes = Utils._AddNumeric(Array(vbEmpty, vbNull, vbDate, vbString, vbBoolean, vbObject, vbVariant, vbByte, vbArray + vbByte))
25 If UBound(pvArgs) &gt;= 0 Then
26 For i = 0 To UBound(pvArgs)
27 If Not Utils._CheckArgument(pvArgs(i), i + 1, vVarTypes(), , False) Then pvArgs(i) = &quot;[TYPE?]&quot;
28 Next i
29 End If
31 Dim sOutput As String, sArg As String
32 sOutput = &quot;&quot;
33 For i = 0 To UBound(pvArgs)
34 sArg = Replace(Utils._CStr(pvArgs(i), _A2B_.DebugPrintShort), &quot;\;&quot;, &quot;;&quot;)
35 &apos; Add argument to output
36 If i = 0 Then
37 sOutput = sArg
38 Else
39 sOutput = sOutput &amp; Space(cstTab - (Len(sOutput) Mod cstTab)) &amp; sArg
40 End If
41 Next i
43 TraceLog(TRACEANY, sOutput, False)
45 Exit_Sub:
46 Utils._ResetCalledSub(&quot;DebugPrint&quot;)
47 Exit Sub
48 End Sub &apos; DebugPrint V0.9.5
50 REM -----------------------------------------------------------------------------------------------------------------------
51 REM --- PYTHON WRAPPERS ---
52 REM -----------------------------------------------------------------------------------------------------------------------
54 REM -----------------------------------------------------------------------------------------------------------------------
55 Public Function PythonEventsWrapper(Optional poEvent As Variant) As Variant
56 &apos; Python wrapper when Application.Events() method is invoked
57 &apos; The ParamArray mechanism empties UNO objects when they are member of the arguments list
58 &apos; As a workaround, the Application.Events function is executed directly
60 If _ErrorHandler() Then On Local Error GoTo Exit_Function &apos; Do never interrupt
61 PythonEventsWrapper = Null
63 Dim vReturn As Variant, vArray As Variant
64 Const cstObject = 1
66 vReturn = Application.Events(poEvent)
67 vArray = Array(cstObject, _A2B_.AddPython(vReturn), vReturn._Type)
69 PythonEventsWrapper = vArray
71 Exit_Function:
72 Exit Function
73 End Function &apos; PythonEventsWrapper V6.4
75 REM -----------------------------------------------------------------------------------------------------------------------
76 Public Function PythonWrapper(ByVal pvCallType As Variant _
77 , ByVal pvObject As Variant _
78 , ByVal pvScript As Variant _
79 , ParamArray pvArgs() As Variant _
80 ) As Variant
81 &apos; Called from Python to apply
82 &apos; - on object with entry pvObject in PythonCache
83 &apos; Conventionally: -1 = Application
84 &apos; -2 = DoCmd
85 &apos; - a script pvScript which type is described by pvCallType
86 &apos; - with arguments pvArgs(0)... (max. 8 for object methods)
87 &apos; The value returned by the method/property is encapsulated in an array
88 &apos; [0] =&gt; 0 = scalar or array returned by the method
89 &apos; =&gt; 1 = basic object returned by the method
90 &apos; =&gt; 2 = a null value
91 &apos; [1] =&gt; the object reference or the returned value (complemented with arguments passed by reference, if any) or Null
92 &apos; [2] =&gt; the object type or Null
93 &apos; [3] =&gt; the object name, if any
94 &apos; or, when pvCallType == vbUNO, as the UNO object returned by the property
96 Dim vReturn As Variant, vArray As Variant
97 Dim vObject As Variant, sScript As String, sModule As String
98 Dim i As Integer, iNbArgs As Integer, vArg As Variant, vArgs() As Variant
100 Const cstApplication = -1, cstDoCmd = -2
101 Const cstScalar = 0, cstObject = 1, cstNull = 2, cstUNO = 3
103 &apos;Conventional special values
104 Const cstNoArgs = &quot;+++NOARGS+++&quot;, cstSymEmpty = &quot;+++EMPTY+++&quot;, cstSymNull = &quot;+++NULL+++&quot;, cstSymMissing = &quot;+++MISSING+++&quot;
106 &apos;https://support.office.com/en-us/article/CallByName-fonction-49ce9475-c315-4f13-8d35-e98cfe98729a
107 &apos;Determines the pvCallType
108 Const vbGet = 2, vbLet = 4, vbMethod = 1, vbSet = 8, vbUNO = 16
110 If _ErrorHandler() Then On Local Error GoTo Error_Function
111 PythonWrapper = Null
113 &apos;Reinterpret arguments one by one into vArgs, examine iso-dates and conventional NoArgs/Empty/Null values
114 iNbArgs = -1
115 vArgs = Array()
116 If UBound(pvArgs) &gt;= 0 Then
117 For i = 0 To UBound(pvArgs)
118 vArg = pvArgs(i)
119 If i = 0 And VarType(vArg) = vbString Then
120 If vArg = cstNoArgs Then Exit For
121 End If
122 If VarType(vArg) = vbString Then
123 If vArg = cstSymEmpty Then
124 vArg = Empty
125 ElseIf vArg = cstSymNull Then
126 vArg = Null
127 ElseIf vArg = cstSymMissing Then
128 Exit For &apos; Next arguments must be missing also
129 Else
130 vArg = _CDate(vArg)
131 End If
132 End If
133 iNbArgs = iNbArgs + 1
134 ReDim Preserve vArgs(iNbArgs)
135 vArgs(iNbArgs) = vArg
136 Next i
137 End If
139 &apos;Check pvObject
140 Select Case pvObject &apos; Always numeric
141 Case cstApplication
142 sModule = &quot;Application&quot;
143 Select Case pvScript
144 Case &quot;AllDialogs&quot; : If iNbArgs &lt; 0 Then vReturn = Application.AllDialogs() Else vReturn = Application.AllDialogs(vArgs(0))
145 Case &quot;AllForms&quot; : If iNbArgs &lt; 0 Then vReturn = Application.AllForms() Else vReturn = Application.AllForms(vArgs(0))
146 Case &quot;AllModules&quot; : If iNbArgs &lt; 0 Then vReturn = Application.AllModules() Else vReturn = Application.AllModules(vArgs(0))
147 Case &quot;CloseConnection&quot;
148 vReturn = Application.CloseConnection()
149 Case &quot;CommandBars&quot; : If iNbArgs &lt; 0 Then vReturn = Application.CommandBars() Else vReturn = Application.CommandBars(vArgs(0))
150 Case &quot;CurrentDb&quot; : vReturn = Application.CurrentDb()
151 Case &quot;CurrentUser&quot; : vReturn = Application.CurrentUser()
152 Case &quot;DAvg&quot; : vReturn = Application.DAvg(vArgs(0), vArgs(1), vArgs(2))
153 Case &quot;DCount&quot; : vReturn = Application.DCount(vArgs(0), vArgs(1), vArgs(2))
154 Case &quot;DLookup&quot; : vReturn = Application.DLookup(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
155 Case &quot;DMax&quot; : vReturn = Application.DMax(vArgs(0), vArgs(1), vArgs(2))
156 Case &quot;DMin&quot; : vReturn = Application.DMin(vArgs(0), vArgs(1), vArgs(2))
157 Case &quot;DStDev&quot; : vReturn = Application.DStDev(vArgs(0), vArgs(1), vArgs(2))
158 Case &quot;DStDevP&quot; : vReturn = Application.DStDevP(vArgs(0), vArgs(1), vArgs(2))
159 Case &quot;DSum&quot; : vReturn = Application.DSum(vArgs(0), vArgs(1), vArgs(2))
160 Case &quot;DVar&quot; : vReturn = Application.DVar(vArgs(0), vArgs(1), vArgs(2))
161 Case &quot;DVarP&quot; : vReturn = Application.DVarP(vArgs(0), vArgs(1), vArgs(2))
162 Case &quot;Forms&quot; : If iNbArgs &lt; 0 Then vReturn = Application.Forms() Else vReturn = Application.Forms(vArgs(0))
163 Case &quot;getObject&quot; : vReturn = Application.getObject(vArgs(0))
164 Case &quot;getValue&quot; : vReturn = Application.getValue(vArgs(0))
165 Case &quot;HtmlEncode&quot; : vReturn = Application.HtmlEncode(vArgs(0), vArgs(1))
166 Case &quot;OpenDatabase&quot; : vReturn = Application.OpenDatabase(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
167 Case &quot;ProductCode&quot; : vReturn = Application.ProductCode()
168 Case &quot;setValue&quot; : vReturn = Application.setValue(vArgs(0), vArgs(1))
169 Case &quot;SysCmd&quot; : vReturn = Application.SysCmd(vArgs(0), vArgs(1), vARgs(2))
170 Case &quot;TempVars&quot; : If iNbArgs &lt; 0 Then vReturn = Application.TempVars() Else vReturn = Application.TempVars(vArgs(0))
171 Case &quot;Version&quot; : vReturn = Application.Version()
172 Case Else
173 GoTo Error_Proc
174 End Select
175 Case cstDoCmd
176 sModule = &quot;DoCmd&quot;
177 Select Case pvScript
178 Case &quot;ApplyFilter&quot; : vReturn = DoCmd.ApplyFilter(vArgs(0), vArgs(1), vArgs(2))
179 Case &quot;Close&quot; : vReturn = DoCmd.mClose(vArgs(0), vArgs(1), vArgs(2))
180 Case &quot;CopyObject&quot; : vReturn = DoCmd.CopyObject(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
181 Case &quot;FindNext&quot; : vReturn = DoCmd.FindNext()
182 Case &quot;FindRecord&quot; : vReturn = DoCmd.FindRecord(vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6))
183 Case &quot;GetHiddenAttribute&quot;
184 vReturn = DoCmd.GetHiddenAttribute(vArgs(0), vArgs(1))
185 Case &quot;GoToControl&quot; : vReturn = DoCmd.GoToControl(vArgs(0))
186 Case &quot;GoToRecord&quot; : vReturn = DoCmd.GoToRecord(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
187 Case &quot;Maximize&quot; : vReturn = DoCmd.Maximize()
188 Case &quot;Minimize&quot; : vReturn = DoCmd.Minimize()
189 Case &quot;MoveSize&quot; : vReturn = DoCmd.MoveSize(vArgs(0), vArgs(1), vArgs(2), vArgs(3))
190 Case &quot;OpenForm&quot; : vReturn = DoCmd.OpenForm(vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6))
191 Case &quot;OpenQuery&quot; : vReturn = DoCmd.OpenQuery(vArgs(0), vArgs(1), vArgs(2))
192 Case &quot;OpenReport&quot; : vReturn = DoCmd.OpenReport(vArgs(0), vArgs(1))
193 Case &quot;OpenSQL&quot; : vReturn = DoCmd.OpenSQL(vArgs(0), vArgs(1))
194 Case &quot;OpenTable&quot; : vReturn = DoCmd.OpenTable(vArgs(0), vArgs(1), vArgs(2))
195 Case &quot;OutputTo&quot; : vReturn = DoCmd.OutputTo(vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7))
196 Case &quot;Quit&quot; : _A2B_.CalledSub = &quot;Quit&quot; : GoTo Error_Action
197 Case &quot;RunApp&quot; : vReturn = DoCmd.RunApp(vArgs(0))
198 Case &quot;RunCommand&quot; : vReturn = DoCmd.RunCommand(vArgs(0))
199 Case &quot;RunSQL&quot; : vReturn = DoCmd.RunSQL(vArgs(0), vArgs(1))
200 Case &quot;SelectObject&quot; : vReturn = DoCmd.SelectObject(vArgs(0), vArgs(1), vArgs(2))
201 Case &quot;SendObject&quot; : vReturn = DoCmd.SendObject(vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7), vArgs(8), vArgs(9))
202 Case &quot;SetHiddenAttribute&quot;
203 vReturn = DoCmd.SetHiddenAttribute(vArgs(0), vArgs(1), vArgs(2))
204 Case &quot;SetOrderBy&quot; : vReturn = DoCmd.SetOrderBy(vArgs(0), vArgs(1))
205 Case &quot;ShowAllRecords&quot;
206 vReturn = DoCmd.ShowAllRecords()
207 Case Else
208 GoTo Error_Proc
209 End Select
210 Case Else
211 &apos; Locate targeted object
212 If pvObject &gt; UBound(_A2B_.PythonCache) Or pvObject &lt; 0 Then GoTo Error_Object
213 Set vObject = _A2B_.PythonCache(pvObject)
214 If IsNull(vObject) Then
215 If pvScript = &quot;Dispose&quot; Then GoTo Exit_Function Else GoTo Error_Object
216 End If
217 &apos; Preprocessing
218 sScript = pvScript
219 sModule = vObject._Type
220 Select Case sScript
221 Case &quot;Add&quot;
222 If vObject._Type = &quot;COLLECTION&quot; And vObject._CollType = COLLTABLEDEFS Then vArgs = Array(_A2B_.PythonCache(vArgs(0)))
223 Case &quot;Close&quot;
224 sSCript = &quot;mClose&quot;
225 Case &quot;Type&quot;
226 sScript = &quot;pType&quot;
227 Case Else
228 End Select
229 &apos; Execute method
230 Select Case UBound(vArgs) &apos; Dirty but ... CallByName does not support an array of arguments or return values
231 Case -1
232 If pvCallType = vbUNO Then
233 With vObject
234 Select Case sScript &apos; List all properties that should be called directly (UNO)
235 Case &quot;BoundField&quot; : vReturn = .BoundField
236 Case &quot;Column&quot; : vReturn = .Column
237 Case &quot;Connection&quot; : vReturn = .Connection
238 case &quot;ContainerWindow&quot; : vReturn = .ContainerWindow
239 Case &quot;ControlModel&quot; : vReturn = .ControlModel
240 Case &quot;ControlView&quot; : vReturn = .ControlView
241 Case &quot;DatabaseForm&quot; : vReturn = .DatabaseForm
242 Case &quot;Document&quot; : vReturn = .Document
243 Case &quot;FormsCollection&quot; : vReturn = .FormsCollection
244 Case &quot;LabelControl&quot; : vReturn = .LabelControl
245 Case &quot;MetaData&quot; : vReturn = .MetaData
246 Case &quot;ParentComponent&quot; : vReturn = .ParentComponent
247 Case &quot;Query&quot; : vReturn = .Query
248 Case &quot;RowSet&quot; : vReturn = .RowSet
249 Case &quot;Table&quot; : vReturn = .Table
250 Case &quot;UnoDialog&quot; : vReturn = .UnoDialog
251 Case Else
252 End Select
253 End With
254 ElseIf sScript = &quot;ItemData&quot; Then &apos; List all properties that should be called directly (arrays not supported by CallByName)
255 vReturn = vObject.ItemData
256 ElseIf sScript = &quot;LinkChildFields&quot; Then
257 vReturn = vObject.LinkChildFields
258 ElseIf sScript = &quot;LinkMasterFields&quot; Then
259 vReturn = vObject.LinkMasterFields
260 ElseIf sScript = &quot;OpenArgs&quot; Then
261 vReturn = vObject.OpenArgs
262 ElseIf sScript = &quot;Selected&quot; Then
263 vReturn = vObject.Selected
264 ElseIf sScript = &quot;Value&quot; Then
265 vReturn = vObject.Value
266 Else
267 vReturn = CallByName(vObject, sScript, pvCallType)
268 End If
269 Case 0
270 Select Case sScript
271 Case &quot;AppendChunk&quot; &apos; Arg is a vector, not supported by CallByName
272 vReturn = vObject.GetChunk(vArgs(0), vArgs(1))
273 Case &quot;GetRows&quot; &apos; Returns an array, not supported by CallByName
274 vReturn = vObject.GetRows(vArgs(0), True) &apos; Force iso dates
275 Case Else
276 vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0))
277 End Select
278 Case 1
279 Select Case sScript
280 Case &quot;GetChunk&quot; &apos; Returns a vector, not supported by CallByName
281 vReturn = vObject.GetChunk(vArgs(0), vArgs(1))
282 Case Else
283 vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1))
284 End Select
285 Case 2 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1), vArgs(2))
286 Case 3 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1), vArgs(2), vArgs(3))
287 Case 4 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4))
288 Case 5 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5))
289 Case 6 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6))
290 Case 7 : vReturn = CallByName(vObject, sScript, pvCallType, vArgs(0), vArgs(1), vArgs(2), vArgs(3), vArgs(4), vArgs(5), vArgs(6), vArgs(7))
291 End Select
292 &apos; Postprocessing
293 Select Case pvScript
294 Case &quot;Close&quot;, &quot;Dispose&quot;, &quot;Terminate&quot;
295 Set _A2B_.PythonCache(pvObject) = Nothing
296 Case &quot;Move&quot;, &quot;MoveFirst&quot;, &quot;MoveLast&quot;, &quot;MoveNext&quot;, &quot;MovePrevious&quot; &apos; Pass the new BOF, EOF values (binary format)
297 If vObject._Type = &quot;RECORDSET&quot; Then
298 vReturn = (Iif(vObject.BOF, 1, 0) * 2 + Iif(vObject.EOF, 1, 0)) * Iif(vReturn, 1, -1)
299 End If
300 Case &quot;Find&quot; &apos; Store in array the arguments passed by reference
301 If vObject._Type = &quot;MODULE&quot; And vReturn = True Then
302 vReturn = Array(vReturn, vArgs(1), vArgs(2), vArgs(3), vArgs(4))
303 End If
304 Case &quot;ProcOfLine&quot; &apos; Store in array the arguments passed by reference
305 vReturn = Array(vReturn, vArgs(1))
306 Case Else
307 End Select
308 End Select
310 &apos; Structure the returned array
311 If pvCallType = vbUNO Then
312 vArray = vReturn
313 Else
314 If IsNull(vReturn) Then
315 vArray = Array(cstNull, Null, Null)
316 ElseIf IsObject(vReturn) Then
317 Select Case vReturn._Type
318 Case &quot;COLLECTION&quot;, &quot;COMMANDBARCONTROL&quot;, &quot;EVENT&quot;
319 vArray = Array(cstObject, _A2B_.AddPython(vReturn), vReturn._Type)
320 Case Else
321 vArray = Array(cstObject, _A2B_.AddPython(vReturn), vReturn._Type, vReturn.Name)
322 End Select
323 Else
324 If VarType(vReturn) = vbDate Then
325 vArray = Array(cstScalar, _CStr(vReturn), Null)
326 ElseIf VarType(vReturn) = vbBigint Then &apos; Could happen for big integer database fields
327 vArray = Array(cstScalar, CLng(vReturn), Null)
328 Else
329 vArray = Array(cstScalar, vReturn, Null)
330 End If
331 End If
332 End If
334 PythonWrapper = vArray
336 Exit_Function:
337 Exit Function
338 Error_Function:
339 TraceError(TRACEABORT, Err, &quot;PythonWrapper&quot;, Erl)
340 GoTo Exit_Function
341 Error_Object:
342 TraceError(TRACEFATAL, ERROBJECTNOTFOUND, &quot;Python Wrapper (&quot; &amp; pvScript &amp; &quot;)&quot;, 0, , Array(_GetLabel(&quot;OBJECT&quot;), &quot;#&quot; &amp; pvObject))
343 GoTo Exit_Function
344 Error_Action:
345 TraceError(TRACEFATAL, ERRACTION, Utils._CalledSub(), 0)
346 GoTo Exit_Function
347 Error_Proc:
348 TraceError(TRACEFATAL, ERRPROCEDURENOTFOUND, &quot;Python Wrapper&quot;, 0, , Array(pvScript, sModule))
349 GoTo Exit_Function
350 End Function &apos; PythonWrapper V6.4
352 REM -----------------------------------------------------------------------------------------------------------------------
353 REM --- PYTHON HELPER FUNCTIONS ---
354 REM -----------------------------------------------------------------------------------------------------------------------
356 REM -----------------------------------------------------------------------------------------------------------------------
357 Public Function PyConvertFromUrl(ByVal pvFile As Variant) As String
358 &apos; Convenient function to have common conversions of filenames from/to url notations both in Python and Basic
360 On Local Error GoTo Exit_Function
361 PyConvertFromUrl = &quot;&quot;
362 If Not Utils._CheckArgument(pvFile, 1, vbString) Then Goto Exit_Function
364 PyConvertFromUrl = ConvertFromUrl(pvFile)
366 Exit_Function:
367 Exit Function
368 End Function &apos; PyConvertFromUrl V6.4
370 REM -----------------------------------------------------------------------------------------------------------------------
371 Public Function PyConvertToUrl(ByVal pvFile As Variant) As String
372 &apos; Convenient function to have common conversions of filenames from/to url notations both in Python and Basic
374 On Local Error GoTo Exit_Function
375 PyConvertToUrl = &quot;&quot;
376 If Not Utils._CheckArgument(pvFile, 1, vbString) Then Goto Exit_Function
378 PyConvertToUrl = ConvertToUrl(pvFile)
380 Exit_Function:
381 Exit Function
382 End Function &apos; PyConvertToUrl V6.4
384 REM -----------------------------------------------------------------------------------------------------------------------
385 Public Function PyCreateUnoService(ByVal pvService As Variant) As Variant
386 &apos; Convenient function to create a UNO service in Python
388 On Local Error GoTo Exit_Function
389 Set PyCreateUnoService = Nothing
390 If Not Utils._CheckArgument(pvService, 1, vbString) Then Goto Exit_Function
392 Set PyCreateUnoService = CreateUnoService(pvService)
394 Exit_Function:
395 Exit Function
396 End Function &apos; PyCreateUnoService V6.4
398 REM -----------------------------------------------------------------------------------------------------------------------
399 Public Function PyDateAdd(ByVal pvAdd As Variant _
400 , ByVal pvCount As Variant _
401 , ByVal pvDate As Variant _
402 ) As Variant
403 &apos; Convenient shortcut to useful and easy-to-use Basic date functions
405 Dim vDate As Variant, vNewDate As Variant
406 On Local Error GoTo Exit_Function
407 PyDateAdd = Null
409 If Not Utils._CheckArgument(pvAdd, 1, vbString) Then Goto Exit_Function
410 If Not Utils._CheckArgument(pvCount, 2, Utils._AddNumeric()) Then Goto Exit_Function
411 If Not Utils._CheckArgument(pvDate, 3, vbString) Then Goto Exit_Function
413 vDate = _CDate(pvDate)
414 vNewDate = DateAdd(pvAdd, pvCount, vDate)
415 If VarType(vNewDate) = vbDate Then PyDateAdd = _CStr(vNewDate) Else PyDateAdd = vNewDate
417 Exit_Function:
418 Exit Function
419 End Function &apos; PyDateAdd V6.4
421 REM -----------------------------------------------------------------------------------------------------------------------
422 Public Function PyDateDiff(ByVal pvAdd As Variant _
423 , ByVal pvDate1 As Variant _
424 , ByVal pvDate2 As Variant _
425 , ByVal pvWeekStart As Variant _
426 , ByVal pvYearStart As Variant _
427 ) As Variant
428 &apos; Convenient shortcut to useful and easy-to-use Basic date functions
430 Dim vDate1 As Variant, vDate2 As Variant
431 On Local Error GoTo Exit_Function
432 PyDateDiff = Null
434 If Not Utils._CheckArgument(pvAdd, 1, vbString) Then Goto Exit_Function
435 If Not Utils._CheckArgument(pvDate1, 2, vbString) Then Goto Exit_Function
436 If Not Utils._CheckArgument(pvDate2, 3, vbString) Then Goto Exit_Function
437 If Not Utils._CheckArgument(pvWeekStart, 4, Utils._AddNumeric()) Then Goto Exit_Function
438 If Not Utils._CheckArgument(pvWeekStart, 5, Utils._AddNumeric()) Then Goto Exit_Function
440 vDate1 = _CDate(pvDate1)
441 vDate2 = _CDate(pvDate2)
442 PyDateDiff = DateDiff(pvAdd, vDate1, vDate2, pvWeekStart, pvYearStart)
444 Exit_Function:
445 Exit Function
446 End Function &apos; PyDateDiff V6.4
448 REM -----------------------------------------------------------------------------------------------------------------------
449 Public Function PyDatePart(ByVal pvAdd As Variant _
450 , ByVal pvDate As Variant _
451 , ByVal pvWeekStart As Variant _
452 , ByVal pvYearStart As Variant _
453 ) As Variant
454 &apos; Convenient shortcut to useful and easy-to-use Basic date functions
456 Dim vDate As Variant
457 On Local Error GoTo Exit_Function
458 PyDatePart = Null
460 If Not Utils._CheckArgument(pvAdd, 1, vbString) Then Goto Exit_Function
461 If Not Utils._CheckArgument(pvDate, 2, vbString) Then Goto Exit_Function
462 If Not Utils._CheckArgument(pvWeekStart, 3, Utils._AddNumeric()) Then Goto Exit_Function
463 If Not Utils._CheckArgument(pvWeekStart, 4, Utils._AddNumeric()) Then Goto Exit_Function
465 vDate = _CDate(pvDate)
466 PyDatePart = DatePart(pvAdd, vDate, pvWeekStart, pvYearStart)
468 Exit_Function:
469 Exit Function
470 End Function &apos; PyDatePart V6.4
472 REM -----------------------------------------------------------------------------------------------------------------------
473 Public Function PyDateValue(ByVal pvDate As Variant) As Variant
474 &apos; Convenient shortcut to useful and easy-to-use Basic date functions
476 Dim vDate As Variant
477 On Local Error GoTo Exit_Function
478 PyDateValue = Null
479 If Not Utils._CheckArgument(pvDate, 1, vbString) Then Goto Exit_Function
481 vDate = DateValue(pvDate)
482 If VarType(vDate) = vbDate Then PyDateValue = _CStr(vDate) Else PyDateValue = vDate
484 Exit_Function:
485 Exit Function
486 End Function &apos; PyDateValue V6.4
488 REM -----------------------------------------------------------------------------------------------------------------------
489 Public Function PyFormat(ByVal pvValue As Variant, pvFormat As Variant) As String
490 &apos; Convenient function to format numbers or dates
492 On Local Error GoTo Exit_Function
493 PyFormat = &quot;&quot;
494 If Not Utils._CheckArgument(pvValue, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function
495 pvValue = _CDate(pvValue)
496 If IsEmpty(pvFormat) Then
497 PyFormat = Str(pvValue)
498 Else
499 If Not Utils._CheckArgument(pvFormat, 2, vbString) Then Goto Exit_Function
500 PyFormat = Format(pvValue, pvFormat)
501 End If
503 Exit_Function:
504 Exit Function
505 End Function &apos; PyFormat V6.4
507 REM -----------------------------------------------------------------------------------------------------------------------
508 Public Function PyGetGUIType() As Variant
510 PyGetGUIType = GetGUIType()
512 End Function &apos; PyGetGUIType V6.4
514 REM -----------------------------------------------------------------------------------------------------------------------
515 Public Function PyGetSystemTicks() As Variant
517 PyGetSystemTicks = GetSystemTicks()
519 End Function &apos; PyGetSystemTicks V6.4
521 REM -----------------------------------------------------------------------------------------------------------------------
522 Public Function PyGlobalScope(ByVal pvLib As Variant) As Variant
524 Select Case pvLib
525 Case &quot;Basic&quot;
526 PyGlobalScope = GlobalScope.BasicLibraries()
527 Case &quot;Dialog&quot;
528 PyGlobalScope = GlobalScope.DialogLibraries()
529 Case Else
530 End Select
532 End Function &apos; PyGlobalScope V6.4
534 REM -----------------------------------------------------------------------------------------------------------------------
535 Public Function PyInputBox(ByVal pvText As Variant _
536 , ByVal pvTitle As Variant _
537 , ByVal pvDefault As Variant _
538 , ByVal pvXPos As Variant _
539 , ByVal pvYPos As Variant _
540 ) As Variant
541 &apos; Convenient function to open input box from Python
543 On Local Error GoTo Exit_Function
544 PyInputBox = Null
546 If Not Utils._CheckArgument(pvText, 1, vbString) Then Goto Exit_Function
547 If IsEmpty(pvTitle) Then pvTitle = &quot;&quot;
548 If Not Utils._CheckArgument(pvTitle, 2, vbString) Then Goto Exit_Function
549 If IsEmpty(pvDefault) Then pvDefault = &quot;&quot;
550 If Not Utils._CheckArgument(pvDefault, 3, vbString) Then Goto Exit_Function
552 If IsEmpty(pvXPos) Or IsEmpty(pvYPos) Then
553 PyInputBox = InputBox(pvText, pvTitle, pvDefault)
554 Else
555 If Not Utils._CheckArgument(pvXPos, 4, Utils._AddNumeric()) Then Goto Exit_Function
556 If Not Utils._CheckArgument(pvYPos, 5, Utils._AddNumeric()) Then Goto Exit_Function
557 PyInputBox = InputBox(pvText, pvTitle, pvDefault, pvXPos, pvYPos)
558 End If
560 Exit_Function:
561 Exit Function
562 End Function &apos; PyInputBox V6.4.0
564 REM -----------------------------------------------------------------------------------------------------------------------
565 Public Function PyMsgBox(ByVal pvText As Variant _
566 , ByVal pvType As Variant _
567 , ByVal pvDialogTitle As Variant _
568 ) As Variant
569 &apos; Convenient function to open message box from Python
571 On Local Error GoTo Exit_Function
572 PyMsgBox = Null
574 If Not Utils._CheckArgument(pvText, 1, vbString) Then Goto Exit_Function
575 If IsEmpty(pvType) Then pvType = 0
576 If Not Utils._CheckArgument(pvType, 2, Utils._AddNumeric()) Then Goto Exit_Function
577 If IsEmpty(pvDialogTitle) Then
578 PyMsgBox = MsgBox(pvText, pvType)
579 Else
580 If Not Utils._CheckArgument(pvDialogTitle, 3, vbString) Then Goto Exit_Function
581 PyMsgBox = MsgBox(pvText, pvType, pvDialogTitle)
582 End If
584 Exit_Function:
585 Exit Function
586 End Function &apos; PyMsgBox V6.4.0
588 REM -----------------------------------------------------------------------------------------------------------------------
589 Public Function PyTimer() As Long
590 &apos; Convenient function to call Timer from Python
592 PyTimer = Timer
594 End Function &apos; PyTimer V6.4
596 REM -----------------------------------------------------------------------------------------------------------------------
597 REM --- PRIVATE FUNCTIONS ---
598 REM -----------------------------------------------------------------------------------------------------------------------
600 REM -----------------------------------------------------------------------------------------------------------------------
601 Private Function _CDate(ByVal pvValue As Variant) As Variant
602 &apos; Return a Date type if iso date, otherwise return input
604 Dim vValue As Variant
605 vValue = pvValue
606 If VarType(pvValue) = vbString Then
607 If pvValue &lt;&gt; &quot;&quot; And IsDate(pvValue) Then vValue = CDate(pvValue) &apos; IsDate(&quot;&quot;) gives True !?
608 End If
609 _CDate = vValue
611 End Function
613 </script:module>