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=
"SF_Exception" script:
language=
"StarBasic" script:
moduleType=
"normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === Full documentation is available on https://help.libreoffice.org/ ===
6 REM =======================================================================================================================
11 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
12 ''' Exception (aka SF_Exception)
13 ''' =========
14 ''' Generic singleton class for Basic code debugging and error handling
16 ''' Errors may be generated by
17 ''' the Basic run-time error detection
18 ''' in the ScriptForge code =
> RaiseAbort()
19 ''' in a user code =
> Raise()
20 ''' an error detection implemented
21 ''' in the ScriptForge code =
> RaiseFatal()
22 ''' in a user code =
> Raise() or RaiseWarning()
24 ''' When a run-time error occurs, the properties of the Exception object are filled
25 ''' with information that uniquely identifies the error and information that can be used to handle it
26 ''' The SF_Exception object is in this context similar to the VBA Err object
27 ''' See https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/err-object
28 ''' The Number property identifies the error: it can be a numeric value or a string
29 ''' Numeric values up to
2000 are considered Basic run-time errors
31 ''' The
"console
" logs events, actual variable values, errors, ... It is an easy mean
32 ''' to debug Basic programs especially when the IDE is not usable, f.i. in Calc user defined functions
33 ''' or during control events processing
34 ''' =
> DebugPrint()
36 ''' The usual behaviour of the application when an error occurs is:
37 ''' 1. Log the error in the console
38 ''' 2, Inform the user about the error with either a standard or a customized message
39 ''' 3. Optionally, stop the execution of the current macro
41 ''' Detailed user documentation:
42 ''' https://help.libreoffice.org/latest/en-US/text/sbasic/shared/
03/sf_exception.html?DbPAR=BASIC
43 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
45 REM ================================================================== EXCEPTIONS
48 Const MISSINGARGERROR =
"MISSINGARGERROR
"
49 Const ARGUMENTERROR =
"ARGUMENTERROR
"
50 Const ARRAYERROR =
"ARRAYERROR
"
51 Const FILEERROR =
"FILEERROR
"
54 Const ARRAYSEQUENCEERROR =
"ARRAYSEQUENCEERROR
"
55 Const ARRAYINSERTERROR =
"ARRAYINSERTERROR
"
56 Const ARRAYINDEX1ERROR =
"ARRAYINDEX1ERROR
"
57 Const ARRAYINDEX2ERROR =
"ARRAYINDEX2ERROR
"
58 Const CSVPARSINGERROR =
"CSVPARSINGERROR
"
59 Const CSVOVERFLOWWARNING =
"CSVOVERFLOWWARNING
"
62 Const DUPLICATEKEYERROR =
"DUPLICATEKEYERROR
"
63 Const UNKNOWNKEYERROR =
"UNKNOWNKEYERROR
"
64 Const INVALIDKEYERROR =
"INVALIDKEYERROR
"
67 Const UNKNOWNFILEERROR =
"UNKNOWNFILEERROR
"
68 Const UNKNOWNFOLDERERROR =
"UNKNOWNFOLDERERROR
"
69 Const NOTAFILEERROR =
"NOTAFILEERROR
"
70 Const NOTAFOLDERERROR =
"NOTAFOLDERERROR
"
71 Const OVERWRITEERROR =
"OVERWRITEERROR
"
72 Const READONLYERROR =
"READONLYERROR
"
73 Const NOFILEMATCHERROR =
"NOFILEMATCHFOUND
"
74 Const FOLDERCREATIONERROR =
"FOLDERCREATIONERROR
"
75 Const FILESYSTEMERROR =
"FILESYSTEMERROR
"
78 Const UNKNOWNSERVICEERROR =
"UNKNOWNSERVICEERROR
"
79 Const SERVICESNOTLOADEDERROR =
"SERVICESNOTLOADEDERROR
"
82 Const CALCFUNCERROR =
"CALCFUNCERROR
"
83 Const NOSCRIPTERROR =
"NOSCRIPTERROR
"
84 Const SCRIPTEXECERROR =
"SCRIPTEXECERROR
"
85 Const WRONGEMAILERROR =
"WRONGEMAILERROR
"
86 Const SENDMAILERROR =
"SENDMAILERROR
"
89 Const FILENOTOPENERROR =
"FILENOTOPENERROR
"
90 Const FILEOPENMODEERROR =
"FILEOPENMODEERROR
"
91 Const ENDOFFILEERROR =
"ENDOFFILEERROR
"
94 Const DOCUMENTERROR =
"DOCUMENTERROR
"
95 Const DOCUMENTCREATIONERROR =
"DOCUMENTCREATIONERROR
"
96 Const DOCUMENTOPENERROR =
"DOCUMENTOPENERROR
"
97 Const BASEDOCUMENTOPENERROR =
"BASEDOCUMENTOPENERROR
"
100 Const DOCUMENTDEADERROR =
"DOCUMENTDEADERROR
"
101 Const DOCUMENTSAVEERROR =
"DOCUMENTSAVEERROR
"
102 Const DOCUMENTSAVEASERROR =
"DOCUMENTSAVEASERROR
"
103 Const DOCUMENTREADONLYERROR =
"DOCUMENTREADONLYERROR
"
104 Const DBCONNECTERROR =
"DBCONNECTERROR
"
107 Const CALCADDRESSERROR =
"CALCADDRESSERROR
"
108 Const DUPLICATESHEETERROR =
"DUPLICATESHEETERROR
"
109 Const OFFSETADDRESSERROR =
"OFFSETADDRESSERROR
"
110 Const DUPLICATECHARTERROR =
"DUPLICATECHARTERROR
"
111 Const RANGEEXPORTERROR =
"RANGEEXPORTERROR
"
114 Const CHARTEXPORTERROR =
"CHARTEXPORTERROR
"
117 Const FORMDEADERROR =
"FORMDEADERROR
"
118 Const CALCFORMNOTFOUNDERROR =
"CALCFORMNOTFOUNDERROR
"
119 Const WRITERFORMNOTFOUNDERROR =
"WRITERFORMNOTFOUNDERROR
"
120 Const BASEFORMNOTFOUNDERROR =
"BASEFORMNOTFOUNDERROR
"
121 Const SUBFORMNOTFOUNDERROR =
"SUBFORMNOTFOUNDERROR
"
122 Const FORMCONTROLTYPEERROR =
"FORMCONTROLTYPEERROR
"
125 Const WRITERRANGEERROR =
"WRITERRANGEERROR
"
128 Const DIALOGNOTFOUNDERROR =
"DIALOGNOTFOUNDERROR
"
129 Const DIALOGDEADERROR =
"DIALOGDEADERROR
"
130 Const CONTROLTYPEERROR =
"CONTROLTYPEERROR
"
131 Const TEXTFIELDERROR =
"TEXTFIELDERROR
"
132 Const PAGEMANAGERERROR =
"PAGEMANAGERERROR
"
133 Const DUPLICATECONTROLERROR =
"DUPLICATECONTROLERROR
"
136 Const DBREADONLYERROR =
"DBREADONLYERROR
"
137 Const SQLSYNTAXERROR =
"SQLSYNTAXERROR
"
138 Const SQLSYNTAX2ERROR =
"SQLSYNTAX2ERROR
"
139 Const NOCURRENTRECORDERROR =
"NOCURRENTRECORDERROR
"
140 Const RECORDUPDATEERROR =
"RECORDUPDATEERROR
"
141 Const FIELDEXPORTERROR =
"FIELDEXPORTERROR
"
144 Const PYTHONSHELLERROR =
"PYTHONSHELLERROR
"
147 Const UNITTESTLIBRARYERROR =
"UNITTESTLIBRARYERROR
"
148 Const UNITTESTMETHODERROR =
"UNITTESTMETHODERROR
"
150 REM ============================================================= PRIVATE MEMBERS
152 ' User defined errors
153 Private _Number As Variant
' Error number/code (Integer or String)
154 Private _Source As Variant
' Where the error occurred: a module, a Sub/Function, ...
155 Private _Description As String
' The error message
157 ' System run-time errors
158 Private _SysNumber As Long
' Alias of Err
159 Private _SysSource As Long
' Alias of Erl
160 Private _SysDescription As String
' Alias of Error$
162 REM ============================================================ MODULE CONSTANTS
164 Const RUNTIMEERRORS =
2000 ' Upper limit of Basic run-time errors
165 Const CONSOLENAME =
"ConsoleLines
" ' Name of control in the console dialog
167 REM ===================================================== CONSTRUCTOR/DESTRUCTOR
169 REM -----------------------------------------------------------------------------
170 Public Function Dispose() As Variant
171 Set Dispose = Nothing
172 End Function
' ScriptForge.SF_Exception Explicit destructor
174 REM ================================================================== PROPERTIES
176 REM -----------------------------------------------------------------------------
177 Property Get Description() As Variant
178 ''' Returns the description of the last error that has occurred
179 ''' Example:
180 ''' myException.Description
181 Description = _PropertyGet(
"Description
")
182 End Property
' ScriptForge.SF_Exception.Description (get)
184 REM -----------------------------------------------------------------------------
185 Property Let Description(ByVal pvDescription As Variant)
186 ''' Set the description of the last error that has occurred
187 ''' Example:
188 ''' myException.Description =
"Not smart to divide by zero
"
189 _PropertySet
"Description
", pvDescription
190 End Property
' ScriptForge.SF_Exception.Description (let)
192 REM -----------------------------------------------------------------------------
193 Property Get Number() As Variant
194 ''' Returns the code of the last error that has occurred
195 ''' Example:
196 ''' myException.Number
197 Number = _PropertyGet(
"Number
")
198 End Property
' ScriptForge.SF_Exception.Number (get)
200 REM -----------------------------------------------------------------------------
201 Property Let Number(ByVal pvNumber As Variant)
202 ''' Set the code of the last error that has occurred
203 ''' Example:
204 ''' myException.Number =
11 ' Division by
0
205 _PropertySet
"Number
", pvNumber
206 End Property
' ScriptForge.SF_Exception.Number (let)
208 REM -----------------------------------------------------------------------------
209 Property Get Source() As Variant
210 ''' Returns the location of the last error that has occurred
211 ''' Example:
212 ''' myException.Source
213 Source = _PropertyGet(
"Source
")
214 End Property
' ScriptForge.SF_Exception.Source (get)
216 REM -----------------------------------------------------------------------------
217 Property Let Source(ByVal pvSource As Variant)
218 ''' Set the location of the last error that has occurred
219 ''' Example:
220 ''' myException.Source =
123 ' Line #
123. Source may also be a string
221 _PropertySet
"Source
", pvSource
222 End Property
' ScriptForge.SF_Exception.Source (let)
224 REM -----------------------------------------------------------------------------
225 Property Get ObjectType As String
226 ''' Only to enable object representation
227 ObjectType =
"SF_Exception
"
228 End Property
' ScriptForge.SF_String.ObjectType
230 REM -----------------------------------------------------------------------------
231 Property Get ServiceName As String
232 ''' Internal use
233 ServiceName =
"ScriptForge.Exception
"
234 End Property
' ScriptForge.SF_Exception.ServiceName
236 REM ===================================================================== METHODS
238 REM -----------------------------------------------------------------------------
240 ''' Reset the current error status and clear the SF_Exception object
241 ''' Args:
242 ''' Examples:
243 ''' On Local Error GoTo Catch
244 ''' ' ...
245 ''' Catch:
246 ''' SF_Exception.Clear()
' Deny the error
248 Const cstThisSub =
"Exception.Clear
"
249 Const cstSubArgs =
""
257 ._Description =
""
260 ._SysDescription =
""
268 End Sub
' ScriptForge.SF_Exception.Clear
270 REM -----------------------------------------------------------------------------
271 Public Sub Console(Optional ByVal Modal As Variant, _
272 Optional ByRef _Context As Variant _
274 ''' Display the console messages in a modal or non-modal dialog
275 ''' If the dialog is already active, when non-modal, it is brought to front
276 ''' Args:
277 ''' Modal: Boolean. Default = True
278 ''' _Context: From Python, the XComponentXontext (FOR INTERNAL USE ONLY)
279 ''' Example:
280 ''' SF_Exception.Console()
282 Dim bConsoleActive As Boolean
' When True, dialog is active
283 Dim oModalBtn As Object
' Modal close button
284 Dim oNonModalBtn As Object
' Non modal close button
285 Const cstThisSub =
"Exception.Console
"
286 Const cstSubArgs =
"[Modal=True]
"
288 ' Save Err, Erl, .. values before any On Error ... statement
289 SF_Exception._CaptureSystemError()
290 If SF_Utils._ErrorHandling() Then On Local Error GoTo Finally
' Never interrupt processing
293 If IsMissing(Modal) Or IsEmpty(Modal) Then Modal = True
294 If IsMissing(_Context) Or IsEmpty(_Context) Then _Context = Nothing
295 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
296 If Not SF_Utils._Validate(Modal,
"Modal
", V_BOOLEAN) Then GoTo Finally
301 bConsoleActive = False
302 If Not IsNull(.ConsoleDialog) Then bConsoleActive = .ConsoleDialog._IsStillAlive(False)
' False to not raise an error
303 If bConsoleActive And Modal = False Then
304 ' Bring to front
305 .ConsoleDialog.Activate()
307 ' Initialize dialog and fill with actual data
308 ' The dual modes (modal and non-modal) require to have
2 close buttons o/w only
1 is visible
309 ' - a usual OK button
310 ' - a Default button triggering the Close action
311 Set .ConsoleDialog = CreateScriptService(
"SFDialogs.Dialog
",
"GlobalScope
",
"ScriptForge
",
"dlgConsole
", _Context)
312 ' Setup labels and visibility
313 Set oModalBtn = .ConsoleDialog.Controls(
"CloseModalButton
")
314 Set oNonModalBtn = .ConsoleDialog.Controls(
"CloseNonModalButton
")
315 oModalBtn.Visible = Modal
316 oNonModalBtn.Visible = CBool(Not Modal)
317 ' Load console lines
319 .ConsoleDialog.Execute(Modal)
320 ' Terminate the modal dialog
322 Set .ConsoleControl = .ConsoleControl.Dispose()
323 Set .ConsoleDialog = .ConsoleDialog.Dispose()
329 SF_Utils._ExitFunction(cstThisSub)
331 End Sub
' ScriptForge.SF_Exception.Console
333 REM -----------------------------------------------------------------------------
334 Public Sub ConsoleClear(Optional ByVal Keep)
335 ''' Clear the console keeping an optional number of recent messages
336 ''' Args:
337 ''' Keep: the number of messages to keep
338 ''' If Keep is bigger than the number of messages stored in the console,
339 ''' the console is not cleared
340 ''' Example:
341 ''' SF_Exception.ConsoleClear(
5)
343 Dim lConsole As Long
' UBound of ConsoleLines
344 Const cstThisSub =
"Exception.ConsoleClear
"
345 Const cstSubArgs =
"[Keep=
0]
"
347 ' Save Err, Erl, .. values before any On Error ... statement
348 SF_Exception._CaptureSystemError()
349 If SF_Utils._ErrorHandling() Then On Local Error GoTo Finally
' Never interrupt processing
352 If IsMissing(Keep) Or IsEmpty(Keep) Then Keep =
0
353 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
354 If Not SF_Utils._Validate(Keep,
"Keep
", V_NUMERIC) Then GoTo Finally
360 .ConsoleLines = Array()
362 lConsole = UBound(.ConsoleLines)
363 If Keep
< lConsole +
1 Then .ConsoleLines = SF_Array.Slice(.ConsoleLines, lConsole - Keep +
1)
367 ' If active, the console dialog needs to be refreshed
371 SF_Utils._ExitFunction(cstThisSub)
373 End Sub
' ScriptForge.SF_Exception.ConsoleClear
375 REM -----------------------------------------------------------------------------
376 Public Function ConsoleToFile(Optional ByVal FileName As Variant) As Boolean
377 ''' Export the content of the console to a text file
378 ''' If the file exists and the console is not empty, it is overwritten without warning
379 ''' Args:
380 ''' FileName: the complete file name to export to. If it exists, is overwritten without warning
381 ''' Returns:
382 ''' True if the file could be created
383 ''' Examples:
384 ''' SF_Exception.ConsoleToFile(
"myFile.txt
")
386 Dim bExport As Boolean
' Return value
387 Dim oFile As Object
' Output file handler
388 Dim sLine As String
' A single line
389 Const cstThisSub =
"Exception.ConsoleToFile
"
390 Const cstSubArgs =
"FileName
"
392 ' Save Err, Erl, .. values before any On Error ... statement
393 SF_Exception._CaptureSystemError()
394 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
398 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
399 If Not SF_Utils._ValidateFile(FileName,
"FileName
") Then GoTo Finally
404 If UBound(_SF_.ConsoleLines)
> -
1 Then
405 Set oFile = SF_FileSystem.CreateTextFile(FileName, Overwrite := True)
406 If Not IsNull(oFile) Then
408 For Each sLine In _SF_.ConsoleLines
418 If Not IsNull(oFile) Then Set oFile = oFile.Dispose()
419 ConsoleToFile = bExport
420 SF_Utils._ExitFunction(cstThisSub)
424 End Function
' ScriptForge.SF_Exception.ConsoleToFile
426 REM -----------------------------------------------------------------------------
427 Public Sub DebugDisplay(ParamArray pvArgs() As Variant)
428 ''' Display the list of arguments in a readable form in a message box
429 ''' Arguments are separated by a LINEFEED character
430 ''' The maximum length of each individual argument =
1024 characters
431 ''' Args:
432 ''' Any number of arguments of any type
433 ''' Examples:
434 ''' SF_Exception.DebugDisplay(a, Array(
1,
2,
3), ,
"line1
" & Chr(
10)
& "Line2
", DateSerial(
2020,
04,
09))
436 Dim sOutputMsg As String
' Line to display
437 Dim sOutputCon As String
' Line to write in console
438 Dim sArgMsg As String
' Single argument
439 Dim sArgCon As String
' Single argument
442 Const cstMaxLength =
1024
443 Const cstThisSub =
"Exception.DebugDisplay
"
444 Const cstSubArgs =
"Arg0, [Arg1, ...]
"
446 ' Save Err, Erl, .. values before any On Error ... statement
447 SF_Exception._CaptureSystemError()
448 If SF_Utils._ErrorHandling() Then On Local Error Goto Finally
' Never interrupt processing
449 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
451 ' Build new console line
452 sOutputMsg =
"" : sOutputCon =
""
453 For i =
0 To UBound(pvArgs)
454 If IsError(pvArgs(i)) Then pvArgs(i) =
""
455 sArgMsg = Iif(i =
0,
"", SF_String.sfNEWLINE)
& SF_Utils._Repr(pvArgs(i), cstMaxLength)
'Do not use SF_String.Represent()
456 sArgCon = Iif(i =
0,
"", SF_String.sfTAB)
& SF_Utils._Repr(pvArgs(i), cstMaxLength)
457 sOutputMsg = sOutputMsg
& sArgMsg
458 sOutputCon = sOutputCon
& sArgCon
461 ' Add to actual console
462 _SF_._AddToConsole(SF_String.ExpandTabs(sOutputCon, cstTab))
463 ' Display the message
464 MsgBox(sOutputMsg, MB_OK + MB_ICONINFORMATION,
"DebugDisplay
")
467 SF_Utils._ExitFunction(cstThisSub)
469 End Sub
' ScriptForge.SF_Exception.DebugDisplay
471 REM -----------------------------------------------------------------------------
472 Public Sub DebugPrint(ParamArray pvArgs() As Variant)
473 ''' Print the list of arguments in a readable form in the console
474 ''' Arguments are separated by a TAB character (simulated by spaces)
475 ''' The maximum length of each individual argument =
1024 characters
476 ''' Args:
477 ''' Any number of arguments of any type
478 ''' Examples:
479 ''' SF_Exception.DebugPrint(a, Array(
1,
2,
3), ,
"line1
" & Chr(
10)
& "Line2
", DateSerial(
2020,
04,
09))
481 Dim sOutput As String
' Line to write in console
482 Dim sArg As String
' Single argument
485 Const cstMaxLength =
1024
486 Const cstThisSub =
"Exception.DebugPrint
"
487 Const cstSubArgs =
"Arg0, [Arg1, ...]
"
489 ' Save Err, Erl, .. values before any On Error ... statement
490 SF_Exception._CaptureSystemError()
491 If SF_Utils._ErrorHandling() Then On Local Error Goto Finally
' Never interrupt processing
492 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
494 ' Build new console line
495 sOutput =
""
496 For i =
0 To UBound(pvArgs)
497 If IsError(pvArgs(i)) Then pvArgs(i) =
""
498 sArg = Iif(i =
0,
"", SF_String.sfTAB)
& SF_Utils._Repr(pvArgs(i), cstMaxLength)
'Do not use SF_String.Represent()
499 sOutput = sOutput
& sArg
502 ' Add to actual console
503 _SF_._AddToConsole(SF_String.ExpandTabs(sOutput, cstTab))
506 SF_Utils._ExitFunction(cstThisSub)
508 End Sub
' ScriptForge.SF_Exception.DebugPrint
510 REM -----------------------------------------------------------------------------
511 Public Function GetProperty(Optional ByVal PropertyName As Variant) As Variant
512 ''' Return the actual value of the given property
513 ''' Args:
514 ''' PropertyName: the name of the property as a string
515 ''' Returns:
516 ''' The actual value of the property
517 ''' If the property does not exist, returns Null
518 ''' Exceptions
519 ''' ARGUMENTERROR The property does not exist
520 ''' Examples:
521 ''' myException.GetProperty(
"MyProperty
")
523 Const cstThisSub =
"Exception.GetProperty
"
524 Const cstSubArgs =
""
526 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
530 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
531 If Not SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
535 GetProperty = _PropertyGet(PropertyName)
538 SF_Utils._ExitFunction(cstThisSub)
542 End Function
' ScriptForge.SF_Exception.GetProperty
544 REM -----------------------------------------------------------------------------
545 Public Function Methods() As Variant
546 ''' Return the list of public methods of the Exception service as an array
550 ,
"Console
" _
551 ,
"ConsoleClear
" _
552 ,
"ConsoleToFile
" _
553 ,
"DebugPrint
" _
554 ,
"Raise
" _
555 ,
"RaiseAbort
" _
556 ,
"RaiseFatal
" _
557 ,
"RaiseWarning
" _
560 End Function
' ScriptForge.SF_Exception.Methods
562 REM -----------------------------------------------------------------------------
563 Public Function Properties() As Variant
564 ''' Return the list or properties of the Timer class as an array
566 Properties = Array( _
567 "Description
" _
568 ,
"Number
" _
569 ,
"Source
" _
572 End Function
' ScriptForge.SF_Exception.Properties
574 REM -----------------------------------------------------------------------------
575 Public Sub PythonPrint(ParamArray pvArgs() As Variant)
576 ''' Display the list of arguments in a readable form in the Python console
577 ''' Arguments are separated by a TAB character (simulated by spaces)
578 ''' The maximum length of each individual argument =
1024 characters
579 ''' Args:
580 ''' Any number of arguments of any type
581 ''' Examples:
582 ''' SF_Exception.PythonPrint(a, Array(
1,
2,
3), ,
"line1
" & Chr(
10)
& "Line2
", DateSerial(
2020,
04,
09))
584 Dim sOutput As String
' Line to write in console
585 Dim sArg As String
' Single argument
588 Const cstMaxLength =
1024
589 Const cstPyHelper =
"$
" & "_SF_Exception__PythonPrint
"
590 Const cstThisSub =
"Exception.PythonPrint
"
591 Const cstSubArgs =
"Arg0, [Arg1, ...]
"
593 ' Save Err, Erl, .. values before any On Error ... statement
594 SF_Exception._CaptureSystemError()
595 If SF_Utils._ErrorHandling() Then On Local Error Goto Finally
' Never interrupt processing
596 SF_Utils._EnterFunction(cstThisSub, cstSubArgs)
598 ' Build new console line
599 sOutput =
""
600 For i =
0 To UBound(pvArgs)
601 If IsError(pvArgs(i)) Then pvArgs(i) =
""
602 sArg = Iif(i =
0,
"", SF_String.sfTAB)
& SF_Utils._Repr(pvArgs(i), cstMaxLength)
603 sOutput = sOutput
& sArg
606 ' Add to actual console
607 sOutput = SF_String.ExpandTabs(sOutput, cstTab)
608 _SF_._AddToConsole(sOutput)
609 ' Display the message in the Python shell console
610 With ScriptForge.SF_Session
611 .ExecutePythonScript(.SCRIPTISSHARED, _SF_.PythonHelper
& cstPyHelper, sOutput)
615 SF_Utils._ExitFunction(cstThisSub)
617 End Sub
' ScriptForge.SF_Exception.PythonPrint
619 REM -----------------------------------------------------------------------------
620 Public Sub Raise(Optional ByVal Number As Variant _
621 , Optional ByVal Source As Variant _
622 , Optional ByVal Description As Variant _
624 ''' Generate a run-time error. An error message is displayed to the user and logged
625 ''' in the console. The execution is STOPPED
626 ''' Args:
627 ''' Number: the error number, may be numeric or string
628 ''' If numeric and
<=
2000, it is considered a LibreOffice Basic run-time error (default = Err)
629 ''' Source: the line where the error occurred (default = Erl) or any string describing the location of the error
630 ''' Description: the error message to log in the console and to display to the user
631 ''' Examples:
632 ''' On Local Error GoTo Catch
633 ''' ' ...
634 ''' Catch:
635 ''' SF_Exception.Raise()
' Standard behaviour
636 ''' SF_Exception.Raise(
11)
' Force division by zero
637 ''' SF_Exception.Raise(
"MYAPPERROR
",
"myFunction
",
"Application error
")
638 ''' SF_Exception.Raise(,,
"To divide by zero is not a good idea !
")
640 Dim sMessage As String
' Error message to log and to display
641 Dim L10N As Object
' Alias to LocalizedInterface
642 Const cstThisSub =
"Exception.Raise
"
643 Const cstSubArgs =
"[Number=Err], [Source=Erl], [Description]
"
645 ' Save Err, Erl, .. values before any On Error ... statement
646 SF_Exception._CaptureSystemError()
647 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
650 If IsMissing(Number) Or IsEmpty(Number) Then Number = -
1
651 If IsMissing(Source) Or IsEmpty(Source) Then Source = -
1
652 If IsMissing(Description) Or IsEmpty(Description) Then Description =
""
653 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
654 If Not SF_Utils._Validate(Number,
"Number
", Array(V_STRING, V_NUMERIC)) Then GoTo Finally
655 If Not SF_Utils._Validate(Source,
"Source
", Array(V_STRING, V_NUMERIC)) Then GoTo Finally
656 If Not SF_Utils._Validate(Description,
"Description
", V_STRING) Then GoTo Finally
661 If Number
>=
0 Then .Number = Number
662 If VarType(Source) = V_STRING Then
663 If Len(Source)
> 0 Then .Source = Source
664 ElseIf Source
>=
0 Then
' -
1 = Default =
> no change
667 If Len(Description)
> 0 Then .Description = Description
669 ' Log and display
670 Set L10N = _SF_._GetLocalizedInterface()
671 sMessage = L10N.GetText(
"LONGERRORDESC
", .Number, .Source, .Description)
672 .DebugPrint(sMessage)
673 If _SF_.DisplayEnabled Then MsgBox L10N.GetText(
"ERRORNUMBER
", .Number) _
674 & SF_String.sfNewLine
& L10N.GetText(
"ERRORLOCATION
", .Source) _
675 & SF_String.sfNewLine
& .Description _
676 , MB_OK + MB_ICONSTOP _
677 , L10N.GetText(
"ERRORNUMBER
", .Number)
681 SF_Utils._ExitFunction(cstThisSub)
682 If _SF_.StopWhenError Then
690 End Sub
' ScriptForge.SF_Exception.Raise
692 REM -----------------------------------------------------------------------------
693 Public Sub RaiseAbort(Optional ByVal Source As Variant)
694 ''' Manage a run-time error that occurred inside the ScriptForge piece of software itself.
695 ''' The event is logged.
696 ''' The execution is STOPPED
697 ''' For INTERNAL USE only
698 ''' Args:
699 ''' Source: the line where the error occurred
701 Dim sLocation As String
' Common header in error messages: location of error
702 Dim vLocation As Variant
' Split array (library, module, method)
703 Dim sMessage As String
' Error message to log and to display
704 Dim L10N As Object
' Alias to LocalizedInterface
706 Const cstThisSub =
"Exception.RaiseAbort
"
707 Const cstSubArgs =
"[Source=Erl]
"
709 ' Save Err, Erl, .. values before any On Error ... statement
710 SF_Exception._CaptureSystemError()
711 On Local Error Resume Next
714 If IsMissing(Source) Or IsEmpty(Source) Then Source =
""
719 ' Prepare message header
720 Set L10N = _SF_._GetLocalizedInterface()
721 If Len(_SF_.MainFunction)
> 0 Then
' MainFunction = [Library.]Module.Method
722 vLocation = Split(_SF_.MainFunction,
".
")
723 If UBound(vLocation)
< 2 Then vLocation = Split(
"ScriptForge.
" & _SF_.MainFunction,
".
")
724 sLocation = L10N.GetText(
"VALIDATESOURCE
", vLocation(
0), vLocation(
1), vLocation(
2))
& "\n\n\n
"
726 sLocation =
""
729 ' Log and display
730 sMessage = L10N.GetText(
"LONGERRORDESC
", .Number, .Source, .Description)
731 .DebugPrint(sMessage)
732 If _SF_.DisplayEnabled Then
733 sMessage = sLocation _
734 & L10N.GetText(
"INTERNALERROR
") _
735 & L10N.GetText(
"ERRORLOCATION
", Source
& "/
" & .Source)
& SF_String.sfNewLine
& .Description _
736 & "\n
" & "\n
" & "\n
" & L10N.GetText(
"STOPEXECUTION
")
737 MsgBox SF_String.ExpandTabs(SF_String.Unescape(sMessage), cstTabSize) _
738 , MB_OK + MB_ICONSTOP _
739 , L10N.GetText(
"ERRORNUMBER
", .Number)
747 If _SF_.StopWhenError Then Stop
751 End Sub
' ScriptForge.SF_Exception.RaiseAbort
753 REM -----------------------------------------------------------------------------
754 Public Sub RaiseFatal(Optional ByVal ErrorCode As Variant _
755 , ParamArray pvArgs _
757 ''' Generate a run-time error caused by an anomaly in a user script detected by ScriptForge
758 ''' The message is logged in the console. The execution is STOPPED
759 ''' For INTERNAL USE only
760 ''' Args:
761 ''' ErrorCode: as a string, the unique identifier of the error
762 ''' pvArgs: the arguments to insert in the error message
764 Dim sLocation As String
' Common header in error messages: location of error
765 Dim sService As String
' Service name having detected the error
766 Dim sMethod As String
' Method name having detected the error
767 Dim vLocation As Variant
' Split array (library, module, method)
768 Dim sMessage As String
' Message to log and display
769 Dim L10N As Object
' Alias of LocalizedInterface
770 Dim sAlt As String
' Alternative error messages
771 Dim iButtons As Integer
' MB_OK or MB_YESNO
772 Dim iMsgBox As Integer
' Return value of the message box
775 Const cstThisSub =
"Exception.RaiseFatal
"
776 Const cstSubArgs =
"ErrorCode, [Arg0[, Arg1 ...]]
"
777 Const cstStop =
"⏻
" ' Chr(
9211)
779 ' Save Err, Erl, .. values before any On Error ... statement
780 SF_Exception._CaptureSystemError()
781 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
784 If IsMissing(ErrorCode) Or IsEmpty(ErrorCode) Then ErrorCode =
""
785 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
786 If Not SF_Utils._Validate(ErrorCode,
"ErrorCode
", V_STRING) Then GoTo Finally
790 Set L10N = _SF_._GetLocalizedInterface()
791 ' Location header common to all error messages
792 If Len(_SF_.MainFunction)
> 0 Then
' MainFunction = [Library.]Module.Method
793 vLocation = Split(_SF_.MainFunction,
".
")
794 If UBound(vLocation)
< 2 Then vLocation = Split(
"ScriptForge.
" & _SF_.MainFunction,
".
")
795 sService = vLocation(
1)
796 sMethod = vLocation(
2)
797 sLocation = L10N.GetText(
"VALIDATESOURCE
", vLocation(
0), sService, sMethod) _
798 & "\n
" & L10N.GetText(
"VALIDATEARGS
", _RightCaseArgs(_SF_.MainFunctionArgs))
800 sService =
""
801 sMethod =
""
802 sLocation =
""
806 Select Case UCase(ErrorCode)
807 Case MISSINGARGERROR
' SF_Utils._Validate(Name)
808 pvArgs(
0) = _RightCase(pvArgs(
0))
809 sMessage = sLocation _
810 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
811 & "\n
" & "\n
" & .GetText(
"VALIDATEMISSING
", pvArgs(
0))
812 Case ARGUMENTERROR
' SF_Utils._Validate(Value, Name, Types, Values, CaseSensitive, Class)
813 pvArgs(
1) = _RightCase(pvArgs(
1))
814 sMessage = sLocation _
815 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
1)) _
816 & "\n
" & "\n
" & .GetText(
"VALIDATIONRULES
")
817 If Len(pvArgs(
2))
> 0 Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATETYPES
", pvArgs(
1), pvArgs(
2))
818 If Len(pvArgs(
3))
> 0 Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATEVALUES
", pvArgs(
1), pvArgs(
3))
819 If Len(pvArgs(
5))
> 0 Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATECLASS
", pvArgs(
1), pvArgs(
5))
820 sMessage = sMessage
& "\n
" & "\n
" & .GetText(
"VALIDATEACTUAL
", pvArgs(
1), pvArgs(
0))
821 Case ARRAYERROR
' SF_Utils._ValidateArray(Value, Name, Dimensions, Types, NotNull)
822 pvArgs(
1) = _RightCase(pvArgs(
1))
823 sMessage = sLocation _
824 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
1)) _
825 & "\n
" & "\n
" & .GetText(
"VALIDATIONRULES
") _
826 & "\n
" & .GetText(
"VALIDATEARRAY
", pvArgs(
1))
827 If pvArgs(
2)
> 0 Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATEDIMS
", pvArgs(
1), pvArgs(
2))
828 If Len(pvArgs(
3))
> 0 Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATEALLTYPES
", pvArgs(
1), pvArgs(
3))
829 If pvArgs(
4) Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATENOTNULL
", pvArgs(
1))
830 sMessage = sMessage
& "\n
" & "\n
" & .GetText(
"VALIDATEACTUAL
", pvArgs(
1), pvArgs(
0))
831 Case FILEERROR
' SF_Utils._ValidateFile(Value, Name, WildCards)
832 pvArgs(
1) = _RightCase(pvArgs(
1))
833 sMessage = sLocation _
834 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
1)) _
835 & "\n
" & "\n
" & .GetText(
"VALIDATIONRULES
") _
836 & "\n
" & "\n
" & .GetText(
"VALIDATEFILE
", pvArgs(
1))
837 sAlt =
"VALIDATEFILE
" & SF_FileSystem.FileNaming
838 sMessage = sMessage
& "\n
" & .GetText(sAlt, pvArgs(
1))
839 If pvArgs(
2) Then sMessage = sMessage
& "\n
" & .GetText(
"VALIDATEWILDCARD
", pvArgs(
1))
840 sMessage = sMessage
& "\n
" & "\n
" & .GetText(
"VALIDATEACTUAL
", pvArgs(
1), pvArgs(
0))
841 Case ARRAYSEQUENCEERROR
' SF_Array.RangeInit(From, UpTo, ByStep)
842 sMessage = sLocation _
843 & "\n
" & "\n
" & "\n
" & .GetText(
"ARRAYSEQUENCE
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
844 Case ARRAYINSERTERROR
' SF_Array.AppendColumn/Row/PrependColumn/Row(VectorName, Array_2D, Vector)
845 sMessage = sLocation _
846 & "\n
" & "\n
" & "\n
" & .GetText(
"ARRAYINSERT
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
847 Case ARRAYINDEX1ERROR
' SF_Array.ExtractColumn/Row(IndexName, Array_2D, Index)
848 sMessage = sLocation _
849 & "\n
" & "\n
" & "\n
" & .GetText(
"ARRAYINDEX1
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
850 Case ARRAYINDEX2ERROR
' SF_Array.Slice(From, UpTo)
851 sMessage = sLocation _
852 & "\n
" & "\n
" & "\n
" & .GetText(
"ARRAYINDEX2
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
853 Case CSVPARSINGERROR
' SF_Array.ImportFromCSVFile(FileName, LineNumber, Line)
854 sMessage = sLocation _
855 & "\n
" & "\n
" & "\n
" & .GetText(
"CSVPARSING
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
856 Case DUPLICATEKEYERROR
' SF_Dictionary.Add/ReplaceKey(
"Key
", Key)
857 sMessage = sLocation _
858 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
859 & "\n
" & "\n
" & .GetText(
"DUPLICATEKEY
", pvArgs(
0), pvArgs(
1))
860 Case UNKNOWNKEYERROR
' SF_Dictionary.Remove/ReplaceItem/ReplaceKey(
"Key
", Key)
861 sMessage = sLocation _
862 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
863 & "\n
" & "\n
" & .GetText(
"UNKNOWNKEY
", pvArgs(
0), pvArgs(
1))
864 Case INVALIDKEYERROR
' SF_Dictionary.Add/ReplaceKey(Key)
865 sMessage = sLocation _
866 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
867 & "\n
" & "\n
" & .GetText(
"INVALIDKEY
")
868 Case UNKNOWNFILEERROR
' SF_FileSystem.CopyFile/MoveFile/DeleteFile/CreateScriptService(
"L10N
")(ArgName, Filename)
869 pvArgs(
0) = _RightCase(pvArgs(
0))
870 sMessage = sLocation _
871 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
872 & "\n
" & "\n
" & .GetText(
"UNKNOWNFILE
", pvArgs(
0), pvArgs(
1))
873 Case UNKNOWNFOLDERERROR
' SF_FileSystem.CopyFolder/MoveFolder/DeleteFolder/Files/SubFolders(ArgName, Filename)
874 pvArgs(
0) = _RightCase(pvArgs(
0))
875 sMessage = sLocation _
876 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
877 & "\n
" & "\n
" & .GetText(
"UNKNOWNFOLDER
", pvArgs(
0), pvArgs(
1))
878 Case NOTAFILEERROR
' SF_FileSystem.CopyFile/MoveFile/DeleteFile(ArgName, Filename)
879 pvArgs(
0) = _RightCase(pvArgs(
0))
880 sMessage = sLocation _
881 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
882 & "\n
" & "\n
" & .GetText(
"NOTAFILE
", pvArgs(
0), pvArgs(
1))
883 Case NOTAFOLDERERROR
' SF_FileSystem.CopyFolder/MoveFolder/DeleteFolder/Files/SubFolders(ArgName, Filename)
884 pvArgs(
0) = _RightCase(pvArgs(
0))
885 sMessage = sLocation _
886 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
887 & "\n
" & "\n
" & .GetText(
"NOTAFOLDER
", pvArgs(
0), pvArgs(
1))
888 Case OVERWRITEERROR
' SF_FileSystem.Copy+Move/File+Folder/CreateTextFile/OpenTextFile(ArgName, Filename)
889 pvArgs(
0) = _RightCase(pvArgs(
0))
890 sMessage = sLocation _
891 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
892 & "\n
" & "\n
" & .GetText(
"OVERWRITE
", pvArgs(
0), pvArgs(
1))
893 Case READONLYERROR
' SF_FileSystem.Copy+Move+Delete/File+Folder(ArgName, Filename)
894 pvArgs(
0) = _RightCase(pvArgs(
0))
895 sMessage = sLocation _
896 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
897 & "\n
" & "\n
" & .GetText(
"READONLY
", pvArgs(
0), pvArgs(
1))
898 Case NOFILEMATCHERROR
' SF_FileSystem.Copy+Move+Delete/File+Folder(ArgName, Filename)
899 pvArgs(
0) = _RightCase(pvArgs(
0))
900 sMessage = sLocation _
901 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
902 & "\n
" & "\n
" & .GetText(
"NOFILEMATCH
", pvArgs(
0), pvArgs(
1))
903 Case FOLDERCREATIONERROR
' SF_FileSystem.CreateFolder(ArgName, Filename)
904 pvArgs(
0) = _RightCase(pvArgs(
0))
905 sMessage = sLocation _
906 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
907 & "\n
" & "\n
" & .GetText(
"FOLDERCREATION
", pvArgs(
0), pvArgs(
1))
908 Case FILESYSTEMERROR
' SF_FileSystem.---(ArgName, MethodName, ArgValue)
909 pvArgs(
0) = _RightCase(pvArgs(
0))
910 sMessage = sLocation _
911 & "\n
" & "\n
" & .GetText(
"FILESYSTEM
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
912 Case UNKNOWNSERVICEERROR
' SF_Services.CreateScriptService(ArgName, Value, Library, Service)
913 pvArgs(
0) = _RightCase(pvArgs(
0))
914 sMessage = sLocation _
915 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
916 & "\n
" & "\n
" & .GetText(
"UNKNOWNSERVICE
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
917 Case SERVICESNOTLOADEDERROR
' SF_Services.CreateScriptService(ArgName, Value, Library)
918 pvArgs(
0) = _RightCase(pvArgs(
0))
919 sMessage = sLocation _
920 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
921 & "\n
" & "\n
" & .GetText(
"SERVICESNOTLOADED
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
922 Case CALCFUNCERROR
' SF_Session.ExecuteCalcFunction(CalcFunction)
923 sMessage = sLocation _
924 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", _RightCase(
"CalcFunction
")) _
925 & "\n
" & "\n
" & .GetText(
"CALCFUNC
", pvArgs(
0))
926 Case NOSCRIPTERROR
' SF_Session._GetScript(Language,
"Scope
", Scope,
"Script
", Script)
927 pvArgs(
1) = _RightCase(pvArgs(
1)) : pvArgs(
3) = _RightCase(pvArgs(
3))
928 sMessage = sLocation _
929 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", _RightCase(
"Script
")) _
930 & "\n
" & "\n
" & .GetText(
"NOSCRIPT
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4))
931 Case SCRIPTEXECERROR
' SF_Session.ExecuteBasicScript(
"Script
", Script, Cause)
932 pvArgs(
0) = _RightCase(pvArgs(
0))
933 sMessage = sLocation _
934 & "\n
" & "\n
" & .GetText(
"SCRIPTEXEC
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
935 Case WRONGEMAILERROR
' SF_Session.SendMail(Arg, Email)
936 pvArgs(
0) = _RightCase(pvArgs(
0))
937 sMessage = sLocation _
938 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
939 & "\n
" & "\n
" & .GetText(
"WRONGEMAIL
", pvArgs(
1))
940 Case SENDMAILERROR
' SF_Session.SendMail()
941 sMessage = sLocation _
942 & "\n
" & "\n
" & .GetText(
"SENDMAIL
")
943 Case FILENOTOPENERROR
' SF_TextStream._IsFileOpen(FileName)
944 sMessage = sLocation _
945 & "\n
" & "\n
" & .GetText(
"FILENOTOPEN
", pvArgs(
0))
946 Case FILEOPENMODEERROR
' SF_TextStream._IsFileOpen(FileName)
947 sMessage = sLocation _
948 & "\n
" & "\n
" & .GetText(
"FILEOPENMODE
", pvArgs(
0), pvArgs(
1))
949 Case ENDOFFILEERROR
' SF_TextStream.ReadLine/ReadAll/SkipLine(FileName)
950 sMessage = sLocation _
951 & "\n
" & "\n
" & .GetText(
"ENDOFFILE
", pvArgs(
0))
952 Case DOCUMENTERROR
' SF_UI.GetDocument(ArgName, WindowName)
953 pvArgs(
0) = _RightCase(pvArgs(
0))
954 sMessage = sLocation _
955 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
956 & "\n
" & "\n
" & .GetText(
"DOCUMENT
", pvArgs(
0), pvArgs(
1))
957 Case DOCUMENTCREATIONERROR
' SF_UI.Create(Arg1Name, DocumentType, Arg2Name, TemplateFile)
958 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
959 sMessage = sLocation _
960 & "\n
" & "\n
" & .GetText(
"DOCUMENTCREATION
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
961 Case DOCUMENTOPENERROR
' SF_UI.OpenDocument(Arg1Name, FileName, Arg2Name, Password, Arg3Name, FilterName)
962 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2)) : pvArgs(
4) = _RightCase(pvArgs(
4))
963 sMessage = sLocation _
964 & "\n
" & "\n
" & .GetText(
"DOCUMENTOPEN
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4), pvArgs(
5))
965 Case BASEDOCUMENTOPENERROR
' SF_UI.OpenBaseDocument(Arg1Name, FileName, Arg2Name, RegistrationName)
966 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
967 sMessage = sLocation _
968 & "\n
" & "\n
" & .GetText(
"BASEDOCUMENTOPEN
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
969 Case DOCUMENTDEADERROR
' SF_Document._IsStillAlive(FileName)
970 sMessage = sLocation _
971 & "\n
" & "\n
" & .GetText(
"DOCUMENTDEAD
", pvArgs(
0))
972 Case DOCUMENTSAVEERROR
' SF_Document.Save(Arg1Name, FileName)
973 pvArgs(
0) = _RightCase(pvArgs(
0))
974 sMessage = sLocation _
975 & "\n
" & "\n
" & .GetText(
"DOCUMENTSAVE
", pvArgs(
0), pvArgs(
1))
976 Case DOCUMENTSAVEASERROR
' SF_Document.SaveAs(Arg1Name, FileName, Arg2, Overwrite, Arg3, FilterName)
977 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2)) : pvArgs(
4) = _RightCase(pvArgs(
4))
978 sMessage = sLocation _
979 & "\n
" & "\n
" & .GetText(
"DOCUMENTSAVEAS
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4), pvArgs(
5))
980 Case DOCUMENTREADONLYERROR
' SF_Document.update property(
"Document
", FileName)
981 pvArgs(
0) = _RightCase(pvArgs(
0))
982 sMessage = sLocation _
983 & "\n
" & "\n
" & .GetText(
"DOCUMENTREADONLY
", pvArgs(
0), pvArgs(
1))
984 Case DBCONNECTERROR
' SF_Base.GetDatabase(
"User
", User,
"Password
", Password, FileName)
985 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
986 sMessage = sLocation _
987 & "\n
" & "\n
" & .GetText(
"DBCONNECT
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4))
988 Case CALCADDRESSERROR
' SF_Calc._ParseAddress(Address,
"Range
"/
"Sheet
", Scope, Document)
989 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
990 sMessage = sLocation _
991 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
992 & "\n
" & "\n
" & .GetText(
"CALCADDRESS
" & Iif(Left(pvArgs(
0),
5) =
"Sheet
",
"1",
"2"), pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
993 Case DUPLICATESHEETERROR
' SF_Calc.InsertSheet(arg, SheetName, Document)
994 pvArgs(
0) = _RightCase(pvArgs(
0))
995 sMessage = sLocation _
996 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
997 & "\n
" & "\n
" & .GetText(
"DUPLICATESHEET
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
998 Case OFFSETADDRESSERROR
' SF_Calc.RangeOffset(
"Range
", Range,
"Rows
", Rows,
"Columns
", Columns,
"Height
", Height,
"Width
", Width,
"Document, Document)
999 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2)) : pvArgs(
4) = _RightCase(pvArgs(
4))
1000 pvArgs(
6) = _RightCase(pvArgs(
6)) : pvArgs(
8) = _RightCase(pvArgs(
8)) : pvArgs(
10) = _RightCase(pvArgs(
10))
1001 sMessage = sLocation _
1002 & "\n
" & "\n
" & .GetText(
"OFFSETADDRESS
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4) _
1003 , pvArgs(
5), pvArgs(
6), pvArgs(
7), pvArgs(
8), pvArgs(
9), pvArgs(
10), pvArgs(
11))
1004 Case DUPLICATECHARTERROR
' SF_Calc.CreateChart(chart, ChartName, sheet, SheetName, Document, file)
1005 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
1006 sMessage = sLocation _
1007 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
1008 & "\n
" & "\n
" & .GetText(
"DUPLICATECHART
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4), pvArgs(
5))
1009 Case RANGEEXPORTERROR
' SF_Calc.ExportRangeToFile(Arg1Name, FileName, Arg2, Overwrite)
1010 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
1011 sMessage = sLocation _
1012 & "\n
" & "\n
" & .GetText(
"RANGEEXPORT
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
1013 Case CHARTEXPORTERROR
' SF_Chart.ExportToFile(Arg1Name, FileName, Arg2, Overwrite)
1014 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
1015 sMessage = sLocation _
1016 & "\n
" & "\n
" & .GetText(
"CHARTEXPORT
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
1017 Case FORMDEADERROR
' SF_Form._IsStillAlive(FormName, DocumentName)
1018 sMessage = sLocation _
1019 & "\n
" & "\n
" & .GetText(
"FORMDEAD
", pvArgs(
0), pvArgs(
1))
1020 Case CALCFORMNOTFOUNDERROR
' SF_Calc.Forms(Index, SheetName, Document)
1021 sMessage = sLocation _
1022 & "\n
" & "\n
" & .GetText(
"CALCFORMNOTFOUND
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
1023 Case WRITERFORMNOTFOUNDERROR
' SF_Document.Forms(Index, Document)
1024 sMessage = sLocation _
1025 & "\n
" & "\n
" & .GetText(
"WRITERFORMNOTFOUND
", pvArgs(
0), pvArgs(
1))
1026 Case BASEFORMNOTFOUNDERROR
' SF_Base.Forms(Index, FormDocument, BaseDocument)
1027 sMessage = sLocation _
1028 & "\n
" & "\n
" & .GetText(
"BASEFORMNOTFOUND
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
1029 Case SUBFORMNOTFOUNDERROR
' SF_Form.Subforms(Subform, Mainform)
1030 sMessage = sLocation _
1031 & "\n
" & "\n
" & .GetText(
"SUBFORMNOTFOUND
", pvArgs(
0), pvArgs(
1))
1032 Case FORMCONTROLTYPEERROR
' SF_FormControl._SetProperty(ControlName, FormName, ControlType, Property)
1033 sMessage = sLocation _
1034 & "\n
" & "\n
" & .GetText(
"FORMCONTROLTYPE
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
1035 Case WRITERRANGEERROR
' SF_Writer._ParseRange(TextRange,
"TextRange
", Scope, Document)
1036 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
1037 sMessage = sLocation _
1038 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
1039 & "\n
" & "\n
" & .GetText(
"WRITERRANGE
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
1040 Case DIALOGNOTFOUNDERROR
' SF_Dialog._NewDialog(Service, DialogName, WindowName)
1041 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2)) : pvArgs(
4) = _RightCase(pvArgs(
4))
1042 pvArgs(
6) = _RightCase(pvArgs(
6))
1043 sMessage = sLocation _
1044 & "\n
" & "\n
" & .GetText(
"DIALOGNOTFOUND
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4) _
1045 , pvArgs(
5), pvArgs(
6), pvArgs(
7))
1046 Case DIALOGDEADERROR
' SF_Dialog._IsStillAlive(DialogName)
1047 sMessage = sLocation _
1048 & "\n
" & "\n
" & .GetText(
"DIALOGDEAD
", pvArgs(
0))
1049 Case CONTROLTYPEERROR
' SF_DialogControl._SetProperty(ControlName, DialogName, ControlType, Property)
1050 sMessage = sLocation _
1051 & "\n
" & "\n
" & .GetText(
"CONTROLTYPE
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
1052 Case TEXTFIELDERROR
' SF_DialogControl.WriteLine(ControlName, DialogName)
1053 sMessage = sLocation _
1054 & "\n
" & "\n
" & .GetText(
"TEXTFIELD
", pvArgs(
0), pvArgs(
1))
1055 Case PAGEMANAGERERROR
' SF_Dialog.SetPageManager(PilotsList, TabsList, WizardsList)
1056 sMessage = sLocation _
1057 & "\n
" & "\n
" & .GetText(
"PAGEMANAGER
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3), pvArgs(
4), pvArgs(
5))
1058 Case DUPLICATECONTROLERROR
' SF_Dialog.CreateControl(ControlName, DialogName)
1059 pvArgs(
0) = _RightCase(pvArgs(
0))
1060 sMessage = sLocation _
1061 & "\n
" & "\n
" & "\n
" & .GetText(
"VALIDATEERROR
", pvArgs(
0)) _
1062 & "\n
" & "\n
" & .GetText(
"DUPLICATECONTROL
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
1063 Case DBREADONLYERROR
' SF_Database.RunSql(), SF_Dataset.Delete(), Insert(), Update()
1064 sMessage = sLocation _
1065 & "\n
" & "\n
" & .GetText(
"DBREADONLY
", vLocation(
2))
1066 Case SQLSYNTAXERROR
' SF_Database._ExecuteSql(SQL)
1067 sMessage = sLocation _
1068 & "\n
" & "\n
" & .GetText(
"SQLSYNTAX
", pvArgs(
0))
1069 Case SQLSYNTAX2ERROR
' SF_Dataset.Reload/_Initialize(SQL, Filter, OrderBy)
1070 sMessage = sLocation _
1071 & "\n
" & "\n
" & .GetText(
"SQLSYNTAX2
", pvArgs(
0), pvArgs(
1), pvArgs(
2))
1072 Case NOCURRENTRECORDERROR
' SF_Dataset.Insert/Update/GetValue/Delete
1073 sMessage = sLocation _
1074 & "\n
" & "\n
" & .GetText(
"NOCURRENTRECORD
")
1075 Case RECORDUPDATEERROR
' SF_Dataset.Insert/Update(FieldName, FieldValue, FieldType)
1076 sMessage = sLocation _
1077 & "\n
" & "\n
" & .GetText(
"RECORDUPDATE
", pvArgs(
0), pvArgs(
1), pvARgs(
2))
1078 Case FIELDEXPORTERROR
' SF_Dataset.ExportFieldToFile(Arg1Name, FileName, Arg2, Overwrite)
1079 pvArgs(
0) = _RightCase(pvArgs(
0)) : pvArgs(
2) = _RightCase(pvArgs(
2))
1080 sMessage = sLocation _
1081 & "\n
" & "\n
" & .GetText(
"FIELDEXPORT
", pvArgs(
0), pvArgs(
1), pvArgs(
2), pvArgs(
3))
1082 Case PYTHONSHELLERROR
' SF_Exception.PythonShell (Python only)
1083 sMessage = sLocation _
1084 & "\n
" & "\n
" & .GetText(
"PYTHONSHELL
")
1085 Case UNITTESTLIBRARYERROR
' SFUnitTests._NewUnitTest(LibraryName)
1086 sMessage = sLocation _
1087 & "\n
" & "\n
" & .GetText(
"UNITTESTLIBRARY
", pvArgs(
0))
1088 Case UNITTESTMETHODERROR
' SFUnitTests.SF_UnitTest(Method)
1089 sMessage = sLocation _
1090 & "\n
" & "\n
" & .GetText(
"UNITTESTMETHOD
", pvArgs(
0))
1095 ' Log fatal event
1096 _SF_._AddToConsole(sMessage)
1098 ' Display fatal event, if relevant (default)
1099 If _SF_.DisplayEnabled Then
1100 If _SF_.StopWhenError Then sMessage = sMessage
& "\n
" & "\n
" & "\n
" & L10N.GetText(
"STOPEXECUTION
")
1101 ' Do you need more help ?
1102 If Len(sMethod)
> 0 Then
1103 sMessage = sMessage
& "\n
" & "\n
" & L10N.GetText(
"NEEDMOREHELP
", sMethod)
1104 iButtons = MB_YESNO + MB_DEFBUTTON2
1108 iMsgBox = MsgBox(SF_String.ExpandTabs(SF_String.Unescape(sMessage), cstTabSize) _
1109 , iButtons + MB_ICONEXCLAMATION _
1110 , L10N.GetText(
"ERRORNUMBER
", ErrorCode) _
1112 ' If more help needed ...
1113 If iMsgBox = IDYES Then _OpenHelpInBrowser(sService, sMethod)
1117 SF_Utils._ExitFunction(cstThisSub)
1119 If _SF_.StopWhenError Then Stop
1123 End Sub
' ScriptForge.SF_Exception.RaiseFatal
1125 REM -----------------------------------------------------------------------------
1126 Public Sub RaiseWarning(Optional ByVal Number As Variant _
1127 , Optional ByVal Source As Variant _
1128 , Optional ByVal Description As Variant _
1130 ''' Generate a run-time error. An error message is displayed to the user and logged
1131 ''' in the console. The execution is NOT STOPPED
1132 ''' Args:
1133 ''' Number: the error number, may be numeric or string
1134 ''' If numeric and
<=
2000, it is considered a LibreOffice Basic run-time error (default = Err)
1135 ''' Source: the line where the error occurred (default = Erl) or any string describing the location of the error
1136 ''' Description: the error message to log in the console and to display to the user
1137 ''' Returns:
1138 ''' True if successful. Anyway, the execution continues
1139 ''' Examples:
1140 ''' On Local Error GoTo Catch
1141 ''' ' ...
1142 ''' Catch:
1143 ''' SF_Exception.RaiseWarning()
' Standard behaviour
1144 ''' SF_Exception.RaiseWarning(
11)
' Force division by zero
1145 ''' SF_Exception.RaiseWarning(
"MYAPPERROR
",
"myFunction
",
"Application error
")
1146 ''' SF_Exception.RaiseWarning(,,
"To divide by zero is not a good idea !
")
1148 Dim bStop As Boolean
' Alias for stop switch
1149 Const cstThisSub =
"Exception.RaiseWarning
"
1150 Const cstSubArgs =
"[Number=Err], [Source=Erl], [Description]
"
1152 ' Save Err, Erl, .. values before any On Error ... statement
1153 SF_Exception._CaptureSystemError()
1154 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1157 If IsMissing(Number) Or IsEmpty(Number) Then Number = -
1
1158 If IsMissing(Source) Or IsEmpty(Source) Then Source = -
1
1159 If IsMissing(Description) Or IsEmpty(Description) Then Description =
""
1160 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1161 If Not SF_Utils._Validate(Number,
"Number
", Array(V_STRING, V_NUMERIC, V_EMPTY)) Then GoTo Finally
1162 If Not SF_Utils._Validate(Source,
"Source
", Array(V_STRING, V_NUMERIC, V_EMPTY)) Then GoTo Finally
1163 If Not SF_Utils._Validate(Description,
"Description
", V_STRING) Then GoTo Finally
1167 bStop = _SF_.StopWhenError
' Store current value to reset it before leaving the Sub
1168 _SF_.StopWhenError = False
1169 SF_Exception.Raise(Number, Source, Description)
1172 SF_Utils._ExitFunction(cstThisSub)
1173 _SF_.StopWhenError = bStop
1177 End Sub
' ScriptForge.SF_Exception.RaiseWarning
1179 REM -----------------------------------------------------------------------------
1180 Public Function SetProperty(Optional ByVal PropertyName As Variant _
1181 , Optional ByRef Value As Variant _
1183 ''' Set a new value to the given property
1184 ''' Args:
1185 ''' PropertyName: the name of the property as a string
1186 ''' Value: its new value
1187 ''' Exceptions
1188 ''' ARGUMENTERROR The property does not exist
1190 Const cstThisSub =
"Exception.SetProperty
"
1191 Const cstSubArgs =
"PropertyName, Value
"
1193 If SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
1197 If SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
1198 If Not SF_Utils._Validate(PropertyName,
"PropertyName
", V_STRING, Properties()) Then GoTo Catch
1202 SetProperty = _PropertySet(PropertyName, Value)
1205 SF_Utils._ExitFunction(cstThisSub)
1209 End Function
' ScriptForge.SF_Exception.SetProperty
1211 REM =========================================================== PRIVATE FUNCTIONS
1213 REM -----------------------------------------------------------------------------
1214 Private Sub _CaptureSystemError()
1215 ''' Store system error status in system error properties
1216 ''' Called at each invocation of an error management property or method
1217 ''' Reset by SF_Exception.Clear()
1219 If Err
> 0 And _SysNumber =
0 Then
1222 _SysDescription = Error$
1225 End Sub
' ScriptForge.SF_Exception._CaptureSystemError
1227 REM -----------------------------------------------------------------------------
1228 Public Sub _CloseConsole(Optional ByRef poEvent As Object)
1229 ''' Close the console when opened in non-modal mode
1230 ''' Triggered by the CloseNonModalButton from the dlgConsole dialog
1232 On Local Error GoTo Finally
1236 If Not IsNull(.ConsoleDialog) Then
1237 If .ConsoleDialog._IsStillAlive(False) Then
' False to not raise an error
1238 Set .ConsoleControl = .ConsoleControl.Dispose()
1239 Set .ConsoleDialog = .ConsoleDialog.Dispose()
1246 End Sub
' ScriptForge.SF_Exception._CloseConsole
1248 REM -----------------------------------------------------------------------------
1249 Private Sub _ConsoleRefresh()
1250 ''' Reload the content of the console in the dialog
1251 ''' Needed when console first loaded or when totally or partially cleared
1254 ' Do nothing if console inactive
1255 If IsNull(.ConsoleDialog) Then GoTo Finally
1256 If Not .ConsoleDialog._IsStillAlive(False) Then
' False to not generate an error when dead
1257 Set .ConsoleControl = .ConsoleControl.Dispose()
1258 Set .ConsoleDialog = Nothing
1261 ' Store the relevant text in the control
1262 If IsNull(.ConsoleControl) Then Set .ConsoleControl = .ConsoleDialog.Controls(CONSOLENAME)
1263 .ConsoleControl.Value =
""
1264 If UBound(.ConsoleLines)
>=
0 Then .ConsoleControl.WriteLine(Join(.ConsoleLines, SF_String.sfNEWLINE))
1269 End Sub
' ScriptForge.SF_Exception._ConsoleRefresh
1271 REM -----------------------------------------------------------------------------
1272 Private Sub _OpenHelpInBrowser(ByVal psService As String, ByVal psMethod As String)
1273 ''' Open the help page and help anchor related to the given ScriptForge service and method
1275 Dim sUrl As String
' URL to open
1276 Const cstURL =
"https://help.libreoffice.org/latest/en-US/text/sbasic/shared/
03/sf_%
1.html?
&DbPAR=BASIC#%
2"
1278 On Local Error GoTo Finally
' No reason to risk abort here
1280 sUrl = SF_String.ReplaceStr(cstURL, Array(
"%
1",
"%
2"), Array(LCase(psService), psMethod))
1281 SF_Session.OpenUrlInBrowser(sUrl)
1285 End Sub
' ScriptForge.SF_Exception._OpenHelpInBrowser
1287 REM -----------------------------------------------------------------------------
1288 Private Function _PropertyGet(Optional ByVal psProperty As String) As Variant
1289 ''' Return the value of the named property
1290 ''' Args:
1291 ''' psProperty: the name of the property
1293 Dim cstThisSub As String
1294 Const cstSubArgs =
""
1296 cstThisSub =
"SF_Exception.get
" & psProperty
1298 SF_Exception._CaptureSystemError()
1300 Select Case psProperty
1301 Case
"Description
"
1302 If _Description =
"" Then _PropertyGet = _SysDescription Else _PropertyGet = _Description
1303 Case
"Number
"
1304 If IsEmpty(_Number) Then _PropertyGet = _SysNumber Else _PropertyGet = _Number
1305 Case
"Source
"
1306 If IsEmpty(_Source) Then _PropertyGet = _SysSource Else _PropertyGet = _Source
1313 End Function
' ScriptForge.SF_Exception._PropertyGet
1315 REM -----------------------------------------------------------------------------
1316 Private Function _PropertySet(Optional ByVal psProperty As String _
1317 , Optional ByVal pvValue As Variant _
1319 ''' Set a new value to the named property
1320 ''' Applicable only to user defined errors
1321 ''' Args:
1322 ''' psProperty: the name of the property
1323 ''' pvValue: the new value
1325 Dim cstThisSub As String
1326 Const cstSubArgs =
""
1328 cstThisSub =
"SF_Exception.set
" & psProperty
1329 _PropertySet = False
1331 SF_Exception._CaptureSystemError()
1333 ' Argument validation must be manual to preserve system error status
1334 ' If wrong VarType then property set is ignored
1335 Select Case psProperty
1336 Case
"Description
"
1337 If VarType(pvValue) = V_STRING Then _Description = pvValue
1338 Case
"Number
"
1339 Select Case SF_Utils._VarTypeExt(pvValue)
1343 _Number = CLng(pvValue)
1344 If _Number
<= RUNTIMEERRORS And Len(_Description) =
0 Then _Description = Error(_Number)
1349 Case
"Source
"
1350 Select Case SF_Utils._VarTypeExt(pvValue)
1354 _Source = CLng(pvValue)
1364 End Function
' ScriptForge.SF_Exception._PropertySet
1366 REM -----------------------------------------------------------------------------
1367 Private Function _Repr() As String
1368 ''' Convert the Exception instance to a readable string, typically for debugging purposes (DebugPrint ...)
1369 ''' Args:
1370 ''' Return:
1371 ''' "[Exception]: A readable string
"
1373 _Repr =
"[Exception]:
" & _Number
& " (
" & _Description
& ")
"
1375 End Function
' ScriptForge.SF_Exception._Repr
1377 REM -----------------------------------------------------------------------------
1378 Private Function _RightCase(psString As String) As String
1379 ''' Return the input argument in lower case only when the procedure in execution
1380 ''' has been triggered from a Python script
1381 ''' Indeed, Python requires lower case arguments
1382 ''' Args:
1383 ''' psString: probably an identifier in ProperCase
1384 ''' Return:
1385 ''' The input argument in lower case or left unchanged depending on the execution context
1388 If _SF_.TriggeredByPython Then _RightCase = LCase(psString) Else _RightCase = psString
1392 End Function
' ScriptForge.SF_Exception._RightCase
1394 REM -----------------------------------------------------------------------------
1395 Private Function _RightCaseArgs(psString As String) As String
1396 ''' Return the input argument unchanged when the execution context is Basic
1397 ''' When it is Python, the argument names are lowercased.
1398 ''' Args:
1399 ''' psString: one of the cstSubArgs strings located in each official method
1400 ''' Return:
1401 ''' The input string in which the argument names are put in lower case when called from Python scripts
1403 Dim sSubArgs As String
' Return value
1404 Dim vArgs As Variant
' Input string split on the comma character
1405 Dim sSingleArg As String
' Single vArgs item
1406 Dim vSingleArgs As Variant
' vSingleArg split on equal sign
1409 Const cstComma =
",
"
1410 Const cstEqual =
"=
"
1413 If Len(psString) =
0 Then
1414 sSubArgs =
""
1415 ElseIf _SF_.TriggeredByPython Then
1416 vArgs = SF_String.SplitNotQuoted(psString, cstComma, QuoteChar :=
"""")
1417 For i =
0 To UBound(vArgs)
1418 sSingleArg = vArgs(i)
1419 vSingleArgs = Split(sSingleArg, cstEqual)
1420 vSingleArgs(
0) = LCase(vSingleArgs(
0))
1421 vArgs(i) = join(vSingleArgs, cstEqual)
1423 sSubArgs = Join(vArgs, cstComma)
1429 _RightCaseArgs = sSubArgs
1431 End Function
' ScriptForge.SF_Exception._RightCaseArgs
1433 REM ============================================ END OF SCRIPTFORGE.SF_EXCEPTION