Trace.xba 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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="Trace" 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 =======================================================================================================================
  8. Option Explicit
  9. Public Const cstLogMaxEntries = 99
  10. REM Typical Usage
  11. REM TraceLog(&quot;INFO&quot;, &quot;The OK button was pressed&quot;)
  12. REM
  13. REM Typical Usage for error logging
  14. REM Sub MySub()
  15. REM On Local Error GoTo Error_Sub
  16. REM ...
  17. REM Exit_Sub:
  18. REM Exit Sub
  19. REM Error_Sub:
  20. REM TraceError(&quot;ERROR&quot;, Err, &quot;MySub&quot;, Erl)
  21. REM GoTo Exit_Sub
  22. REM End Sub
  23. REM
  24. REM To display the current logged traces and/or to set parameters
  25. REM TraceConsole()
  26. REM -----------------------------------------------------------------------------------------------------------------------
  27. Public Sub TraceConsole()
  28. &apos; Display the Trace dialog with current trace log values and parameter choices
  29. If _ErrorHandler() Then On Local Error Goto Error_Sub
  30. Dim sLineBreak As String, oTraceDialog As Object
  31. sLineBreak = vbNewLine
  32. Set oTraceDialog = CreateUnoDialog(Utils._GetDialogLib().dlgTrace)
  33. oTraceDialog.Title = _GetLabel(&quot;DLGTRACE_TITLE&quot;)
  34. oTraceDialog.Model.HelpText = _GetLabel(&quot;DLGTRACE_HELP&quot;)
  35. Dim oEntries As Object, oTraceLog As Object, oClear As Object, oMinLevel As Object, oNbEntries As Object, oDump As Object
  36. Dim oControl As Object
  37. Dim i As Integer, sText As String, iOKCancel As Integer
  38. Set oNbEntries = oTraceDialog.Model.getByName(&quot;numNbEntries&quot;)
  39. oNbEntries.Value = _A2B_.TraceLogCount
  40. oNbEntries.HelpText = _GetLabel(&quot;DLGTRACE_LBLNBENTRIES_HELP&quot;)
  41. Set oControl = oTraceDialog.Model.getByName(&quot;lblNbEntries&quot;)
  42. oControl.Label = _GetLabel(&quot;DLGTRACE_LBLNBENTRIES_LABEL&quot;)
  43. oControl.HelpText = _GetLabel(&quot;DLGTRACE_LBLNBENTRIES_HELP&quot;)
  44. Set oEntries = oTraceDialog.Model.getByName(&quot;numEntries&quot;)
  45. If _A2B_.TraceLogMaxEntries = 0 Then _A2B_.TraceLogMaxEntries = cstLogMaxEntries
  46. oEntries.Value = _A2B_.TraceLogMaxEntries
  47. oEntries.HelpText = _GetLabel(&quot;DLGTRACE_LBLENTRIES_HELP&quot;)
  48. Set oControl = oTraceDialog.Model.getByName(&quot;lblEntries&quot;)
  49. oControl.Label = _GetLabel(&quot;DLGTRACE_LBLENTRIES_LABEL&quot;)
  50. oControl.HelpText = _GetLabel(&quot;DLGTRACE_LBLENTRIES_HELP&quot;)
  51. Set oDump = oTraceDialog.Model.getByName(&quot;cmdDump&quot;)
  52. oDump.Enabled = 0
  53. oDump.Label = _GetLabel(&quot;DLGTRACE_CMDDUMP_LABEL&quot;)
  54. oDump.HelpText = _GetLabel(&quot;DLGTRACE_CMDDUMP_HELP&quot;)
  55. Set oTraceLog = oTraceDialog.Model.getByName(&quot;txtTraceLog&quot;)
  56. oTraceLog.HelpText = _GetLabel(&quot;DLGTRACE_TXTTRACELOG_HELP&quot;)
  57. If UBound(_A2B_.TraceLogs) &gt;= 0 Then &apos; Array yet initialized
  58. oTraceLog.HardLineBreaks = True
  59. sText = &quot;&quot;
  60. If _A2B_.TraceLogCount &gt; 0 Then
  61. If _A2B_.TraceLogCount &lt; _A2B_.TraceLogMaxEntries Then i = -1 Else i = _A2B_.TraceLogLast
  62. Do
  63. If i &lt; _A2B_.TraceLogMaxEntries - 1 Then i = i + 1 Else i = 0
  64. If Len(_A2B_.TraceLogs(i)) &gt; 11 Then
  65. sText = sText &amp; Right(_A2B_.TraceLogs(i), Len(_A2B_.TraceLogs(i)) - 11) &amp; sLineBreak &apos; Skip date in display
  66. End If
  67. Loop While i &lt;&gt; _A2B_.TraceLogLast
  68. oDump.Enabled = 1 &apos; Enable DumpToFile only if there is something to dump
  69. End If
  70. If Len(sText) &gt; 0 Then sText = Left(sText, Len(sText) - Len(sLineBreak)) &apos; Skip last linefeed
  71. oTraceLog.Text = sText
  72. Else
  73. oTraceLog.Text = _GetLabel(&quot;DLGTRACE_TXTTRACELOG_TEXT&quot;)
  74. End If
  75. Set oClear = oTraceDialog.Model.getByName(&quot;chkClear&quot;)
  76. oClear.State = 0 &apos; Unchecked
  77. oClear.HelpText = _GetLabel(&quot;DLGTRACE_LBLCLEAR_HELP&quot;)
  78. Set oControl = oTraceDialog.Model.getByName(&quot;lblClear&quot;)
  79. oControl.Label = _GetLabel(&quot;DLGTRACE_LBLCLEAR_LABEL&quot;)
  80. oControl.HelpText = _GetLabel(&quot;DLGTRACE_LBLCLEAR_HELP&quot;)
  81. Set oMinLevel = oTraceDialog.Model.getByName(&quot;cboMinLevel&quot;)
  82. If _A2B_.MinimalTraceLevel = 0 Then _A2B_.MinimalTraceLevel = _TraceLevel(TRACEERRORS)
  83. oMinLevel.Text = _TraceLevel(_A2B_.MinimalTraceLevel)
  84. oMinLevel.HelpText = _GetLabel(&quot;DLGTRACE_LBLMINLEVEL_HELP&quot;)
  85. Set oControl = oTraceDialog.Model.getByName(&quot;lblMinLevel&quot;)
  86. oControl.Label = _GetLabel(&quot;DLGTRACE_LBLMINLEVEL_LABEL&quot;)
  87. oControl.HelpText = _GetLabel(&quot;DLGTRACE_LBLMINLEVEL_HELP&quot;)
  88. Set oControl = oTraceDialog.Model.getByName(&quot;cmdOK&quot;)
  89. oControl.Label = _GetLabel(&quot;DLGTRACE_CMDOK_LABEL&quot;)
  90. oControl.HelpText = _GetLabel(&quot;DLGTRACE_CMDOK_HELP&quot;)
  91. Set oControl = oTraceDialog.Model.getByName(&quot;cmdCancel&quot;)
  92. oControl.Label = _GetLabel(&quot;DLGTRACE_CMDCANCEL_LABEL&quot;)
  93. oControl.HelpText = _GetLabel(&quot;DLGTRACE_CMDCANCEL_HELP&quot;)
  94. iOKCancel = oTraceDialog.Execute()
  95. Select Case iOKCancel
  96. Case 1 &apos; OK
  97. If oClear.State = 1 Then
  98. _A2B_.TraceLogs() = Array() &apos; Erase logged traces
  99. _A2B_.TraceLogCount = 0
  100. End If
  101. If oMinLevel.Text &lt;&gt; &quot;&quot; Then _A2B_.MinimalTraceLevel = _TraceLevel(oMinLevel.Text)
  102. If oEntries.Value &lt;&gt; 0 And oEntries.Value &lt;&gt; _A2B_.TraceLogMaxEntries Then
  103. _A2B_.TraceLogs() = Array()
  104. _A2B_.TraceLogMaxEntries = oEntries.Value
  105. End If
  106. Case 0 &apos; Cancel
  107. Case Else
  108. End Select
  109. Exit_Sub:
  110. If Not IsNull(oTraceDialog) Then oTraceDialog.Dispose()
  111. Exit Sub
  112. Error_Sub:
  113. With _A2B_
  114. .TraceLogs() = Array()
  115. .TraceLogCount = 0
  116. .TraceLogLast = 0
  117. End With
  118. GoTo Exit_Sub
  119. End Sub &apos; TraceConsole V1.1.0
  120. REM -----------------------------------------------------------------------------------------------------------------------
  121. Public Sub TraceError(ByVal psErrorLevel As String _
  122. , ByVal piErrorCode As Integer _
  123. , ByVal psErrorProc As String _
  124. , ByVal piErrorLine As Integer _
  125. , ByVal Optional pvMsgBox As Variant _
  126. , ByVal Optional pvArgs As Variant _
  127. )
  128. &apos; Store error code and description in trace rolling buffer
  129. &apos; Display error message if errorlevel &gt;= ERROR
  130. &apos; Stop program execution if errorlevel = FATAL or ABORT
  131. On Local Error Resume Next
  132. If IsEmpty(_A2B_) Then Call Application._RootInit() &apos; First use of Access2Base in current LibO/AOO session
  133. Dim sErrorText As String, sErrorDesc As String, oDb As Object, bMsgBox As Boolean
  134. sErrorDesc = _ErrorMessage(piErrorCode, pvArgs)
  135. sErrorText = _GetLabel(&quot;ERR#&quot;) &amp; CStr(piErrorCode) _
  136. &amp; &quot; (&quot; &amp; sErrorDesc &amp; &quot;) &quot; &amp; _GetLabel(&quot;ERROCCUR&quot;) _
  137. &amp; Iif(piErrorLine &gt; 0, &quot; &quot; &amp; _GetLabel(&quot;ERRLINE&quot;) &amp; &quot; &quot; &amp; CStr(piErrorLine), &quot;&quot;) _
  138. &amp; Iif(psErrorProc &lt;&gt; &quot;&quot;, &quot; &quot; &amp; _GetLabel(&quot;ERRIN&quot;) &amp; &quot; &quot; &amp; psErrorProc, Iif(_A2B_.CalledSub = &quot;&quot;, &quot;&quot;, &quot; &quot; &amp; _Getlabel(&quot;ERRIN&quot;) &amp; &quot; &quot; &amp; _A2B_.CalledSub))
  139. With _A2B_
  140. .LastErrorCode = piErrorCode
  141. .LastErrorLevel = psErrorLevel
  142. .ErrorText = sErrorDesc
  143. .ErrorLongText = sErrorText
  144. .CalledSub = &quot;&quot;
  145. End With
  146. If VarType(pvMsgBox) = vbError Then
  147. bMsgBox = ( psErrorLevel = TRACEERRORS Or psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT )
  148. ElseIf IsMissing(pvMsgBox) Then
  149. bMsgBox = ( psErrorLevel = TRACEERRORS Or psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT )
  150. Else
  151. bMsgBox = pvMsgBox
  152. End If
  153. TraceLog(psErrorLevel, sErrorText, bMsgBox)
  154. &apos; Unexpected error detected in user program or in Access2Base
  155. If psErrorLevel = TRACEFATAL Or psErrorLevel = TRACEABORT Then
  156. If psErrorLevel = TRACEFATAL Then
  157. Set oDb = _A2B_.CurrentDb()
  158. If Not IsNull(oDb) Then oDb.CloseAllrecordsets()
  159. End If
  160. Stop
  161. End If
  162. End Sub &apos; TraceError V0.9.5
  163. REM -----------------------------------------------------------------------------------------------------------------------
  164. Public Function TraceErrorCode() As Variant
  165. &apos; Return the last encountered error code, level, description in an array
  166. &apos; UNPUBLISHED
  167. Dim vError As Variant
  168. With _A2B_
  169. vError = Array( _
  170. .LastErrorCode _
  171. , .LastErrorLevel _
  172. , .ErrorText _
  173. , .ErrorLongText _
  174. )
  175. End With
  176. TraceErrorCode = vError
  177. End Function &apos; TraceErrorCode V6.3
  178. REM -----------------------------------------------------------------------------------------------------------------------
  179. Public Sub TraceLevel(ByVal Optional psTraceLevel As String)
  180. &apos; Set trace level to argument
  181. If _ErrorHandler() Then On Local Error Goto Error_Sub
  182. Select Case True
  183. Case IsMissing(psTraceLevel) : psTraceLevel = &quot;ERROR&quot;
  184. Case psTraceLevel = &quot;&quot; : psTraceLevel = &quot;ERROR&quot;
  185. Case Utils._InList(UCase(psTraceLevel), Array( _
  186. TRACEDEBUG, TRACEINFO, TRACEWARNING, TRACEERRORS, TRACEFATAL, TRACEABORT _
  187. ))
  188. Case Else : Goto Exit_Sub
  189. End Select
  190. _A2B_.MinimalTraceLevel = _TraceLevel(psTraceLevel)
  191. Exit_Sub:
  192. Exit Sub
  193. Error_Sub:
  194. With _A2B_
  195. .TraceLogs() = Array()
  196. .TraceLogCount = 0
  197. .TraceLogLast = 0
  198. End With
  199. GoTo Exit_Sub
  200. End Sub &apos; TraceLevel V0.9.5
  201. REM -----------------------------------------------------------------------------------------------------------------------
  202. Public Sub TraceLog(ByVal psTraceLevel As String _
  203. , ByVal psText As String _
  204. , ByVal Optional pbMsgBox As Boolean _
  205. )
  206. &apos; Store Text in trace log (circular buffer)
  207. If _ErrorHandler() Then On Local Error Goto Error_Sub
  208. Dim vTraceLogs() As String, sTraceLevel As String
  209. With _A2B_
  210. If .MinimalTraceLevel = 0 Then .MinimalTraceLevel = _TraceLevel(TRACEERRORS)
  211. If _TraceLevel(psTraceLevel) &lt; .MinimalTraceLevel Then Exit Sub
  212. If UBound(.TraceLogs) = -1 Then &apos; Initialize TraceLog
  213. If .TraceLogMaxEntries = 0 Then .TraceLogMaxEntries = cstLogMaxEntries
  214. Redim vTraceLogs(0 To .TraceLogMaxEntries - 1)
  215. .TraceLogs = vTraceLogs
  216. .TraceLogCount = 0
  217. .TraceLogLast = -1
  218. If .MinimalTraceLevel = 0 Then .MinimalTraceLevel = _TraceLevel(TRACEERRORS) &apos; Set default value
  219. End If
  220. .TraceLogLast = .TraceLogLast + 1
  221. If .TraceLogLast &gt; UBound(.TraceLogs) Then .TraceLogLast = LBound(.TraceLogs) &apos; Circular buffer
  222. If Len(psTraceLevel) &gt; 7 Then sTraceLevel = Left(psTraceLevel, 7) Else sTraceLevel = psTraceLevel &amp; Spc(8 - Len(psTraceLevel))
  223. .TraceLogs(.TraceLogLast) = Format(Now(), &quot;YYYY-MM-DD hh:mm:ss&quot;) &amp; &quot; &quot; &amp; sTraceLevel &amp; psText
  224. If .TraceLogCount &lt;= UBound(.TraceLogs) Then .TraceLogCount = .TraceLogCount + 1 &apos; # of active entries
  225. End With
  226. If IsMissing(pbMsgBox) Then pbMsgBox = True
  227. Dim iMsgBox As Integer
  228. If pbMsgBox Then
  229. Select Case psTraceLevel
  230. Case TRACEINFO: iMsgBox = vbInformation
  231. Case TRACEERRORS, TRACEWARNING: iMsgBox = vbExclamation
  232. Case TRACEFATAL, TRACEABORT: iMsgBox = vbCritical
  233. Case Else: iMsgBox = vbInformation
  234. End Select
  235. MsgBox psText, vbOKOnly + iMsgBox, psTraceLevel
  236. End If
  237. Exit_Sub:
  238. Exit Sub
  239. Error_Sub:
  240. With _A2B_
  241. .TraceLogs() = Array()
  242. .TraceLogCount = 0
  243. .TraceLogLast = 0
  244. End With
  245. GoTo Exit_Sub
  246. End Sub &apos; TraceLog V0.9.5
  247. REM -----------------------------------------------------------------------------------------------------------------------
  248. REM --- PRIVATE FUNCTIONS ---
  249. REM -----------------------------------------------------------------------------------------------------------------------
  250. Private Sub _DumpToFile(oEvent As Object)
  251. &apos; Execute the Dump To File command from the Trace dialog
  252. &apos; Modified from Andrew Pitonyak&apos;s Base Macro Programming §10.4
  253. If _ErrorHandler() Then On Local Error GoTo Error_Sub
  254. Dim sPath as String, iFileNumber As Integer, i As Integer
  255. sPath = _PromptFilePicker(&quot;txt&quot;)
  256. If sPath &lt;&gt; &quot;&quot; Then &apos; Save button pressed
  257. If UBound(_A2B_.TraceLogs) &gt;= 0 Then &apos; Array yet initialized
  258. iFileNumber = FreeFile()
  259. Open sPath For Append Access Write Lock Read As iFileNumber
  260. If _A2B_.TraceLogCount &gt; 0 Then
  261. If _A2B_.TraceLogCount &lt; _A2B_.TraceLogMaxEntries Then i = -1 Else i = _A2B_.TraceLogLast
  262. Do
  263. If i &lt; _A2B_.TraceLogMaxEntries - 1 Then i = i + 1 Else i = 0
  264. Print #iFileNumber _A2B_.TraceLogs(i)
  265. Loop While i &lt;&gt; _A2B_.TraceLogLast
  266. End If
  267. Close iFileNumber
  268. MsgBox _GetLabel(&quot;SAVECONSOLEENTRIES&quot;), vbOK + vbInformation, _GetLabel(&quot;SAVECONSOLE&quot;)
  269. End If
  270. End If
  271. Exit_Sub:
  272. Exit Sub
  273. Error_Sub:
  274. TraceError(&quot;ERROR&quot;, Err, &quot;DumpToFile&quot;, Erl)
  275. GoTo Exit_Sub
  276. End Sub &apos; DumpToFile V0.8.5
  277. REM -----------------------------------------------------------------------------------------------------------------------
  278. Public Function _ErrorHandler(Optional ByVal pbCheck As Boolean) As Boolean
  279. &apos; Indicate if error handler is activated or not
  280. &apos; When argument present set error handler
  281. If IsEmpty(_A2B_) Then Call Application._RootInit() &apos; First use of Access2Base in current LibO/AOO session
  282. If Not IsMissing(pbCheck) Then _A2B_.ErrorHandler = pbCheck
  283. _ErrorHandler = _A2B_.ErrorHandler
  284. Exit Function
  285. End Function
  286. REM -----------------------------------------------------------------------------------------------------------------------
  287. Private Function _ErrorMessage(ByVal piErrorNumber As Integer, Optional ByVal pvArgs As Variant) As String
  288. &apos; Return error message corresponding to ErrorNumber (standard or not)
  289. &apos; and replaces %0, %1, ... , %9 by psArgs(0), psArgs(1), ...
  290. Dim sErrorMessage As String, i As Integer, sErrLabel
  291. _ErrorMessage = &quot;&quot;
  292. If piErrorNumber &gt; ERRINIT Then
  293. sErrLabel = &quot;ERR&quot; &amp; piErrorNumber
  294. sErrorMessage = _Getlabel(sErrLabel)
  295. If Not IsMissing(pvArgs) Then
  296. If Not IsArray(pvArgs) Then
  297. sErrorMessage = Join(Split(sErrorMessage, &quot;%0&quot;), Utils._CStr(pvArgs, False))
  298. Else
  299. For i = LBound(pvArgs) To UBound(pvArgs)
  300. sErrorMessage = Join(Split(sErrorMessage, &quot;%&quot; &amp; i), Utils._CStr(pvArgs(i), False))
  301. Next i
  302. End If
  303. End If
  304. Else
  305. sErrorMessage = Error(piErrorNumber)
  306. &apos; Most (or all?) error messages terminate with a &quot;.&quot;
  307. If Len(sErrorMessage) &gt; 1 And Right(sErrorMessage, 1) = &quot;.&quot; Then sErrorMessage = Left(sErrorMessage, Len(sErrorMessage)-1)
  308. End If
  309. _ErrorMessage = sErrorMessage
  310. Exit Function
  311. End Function &apos; ErrorMessage V0.8.9
  312. REM -----------------------------------------------------------------------------------------------------------------------
  313. Public Function _PromptFilePicker(ByVal psSuffix As String) As String
  314. &apos; Prompt for output file name
  315. &apos; Return &quot;&quot; if Cancel
  316. &apos; Modified from Andrew Pitonyak&apos;s Base Macro Programming §10.4
  317. If _ErrorHandler() Then On Local Error GoTo Error_Function
  318. Dim oFileDialog as Object, oUcb as object, oPath As Object
  319. Dim iAccept as Integer, sInitPath as String
  320. Set oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
  321. oFileDialog.Initialize(Array(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION))
  322. Set oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
  323. oFileDialog.appendFilter(&quot;*.&quot; &amp; psSuffix, &quot;*.&quot; &amp; psSuffix)
  324. oFileDialog.appendFilter(&quot;*.*&quot;, &quot;*.*&quot;)
  325. oFileDialog.setCurrentFilter(&quot;*.&quot; &amp; psSuffix)
  326. Set oPath = createUnoService(&quot;com.sun.star.util.PathSettings&quot;)
  327. sInitPath = oPath.Work &apos; Probably My Documents
  328. If oUcb.Exists(sInitPath) Then oFileDialog.SetDisplayDirectory(sInitPath)
  329. iAccept = oFileDialog.Execute()
  330. _PromptFilePicker = &quot;&quot;
  331. If iAccept = 1 Then &apos; Save button pressed
  332. _PromptFilePicker = oFileDialog.Files(0)
  333. End If
  334. Exit_Function:
  335. If Not IsEmpty(oFileDialog) And Not IsNull(oFileDialog) Then oFileDialog.Dispose()
  336. Exit Function
  337. Error_Function:
  338. TraceError(&quot;ERROR&quot;, Err, &quot;PromptFilePicker&quot;, Erl)
  339. GoTo Exit_Function
  340. End Function &apos; PromptFilePicker V0.8.5
  341. REM -----------------------------------------------------------------------------------------------------------------------
  342. Public Sub _TraceArguments(Optional psCall As String)
  343. &apos; Process the ERRMISSINGARGUMENTS error
  344. &apos; psCall is present if error detected before call to _SetCalledSub
  345. If Not IsMissing(psCall) Then Utils._SetCalledSub(psCall)
  346. TraceError(TRACEFATAL, ERRMISSINGARGUMENTS, Utils._CalledSub(), 0)
  347. Exit Sub
  348. End Sub &apos; TraceArguments
  349. REM -----------------------------------------------------------------------------------------------------------------------
  350. Private Function _TraceLevel(ByVal pvTraceLevel As Variant) As Variant
  351. &apos; Convert string trace level to numeric value or the opposite
  352. Dim vTraces As Variant, i As Integer
  353. vTraces = Array(TRACEDEBUG, TRACEINFO, TRACEWARNING, TRACEERRORS, TRACEFATAL, TRACEABORT, TRACEANY)
  354. Select Case VarType(pvTraceLevel)
  355. Case vbString
  356. _TraceLevel = 4 &apos; 4 = Default
  357. For i = 0 To UBound(vTraces)
  358. If UCase(pvTraceLevel) = UCase(vTraces(i)) Then
  359. _TraceLevel = i + 1
  360. Exit For
  361. End If
  362. Next i
  363. Case vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbBigint, vbDecimal
  364. If pvTraceLevel &lt; 1 Or pvTraceLevel &gt; UBound(vTraces) + 1 Then _TraceLevel = TRACEERRORS Else _TraceLevel = vTraces(pvTraceLevel - 1)
  365. End Select
  366. End Function &apos; TraceLevel
  367. </script:module>