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=
"Utils" script:
language=
"StarBasic">REM =======================================================================================================================
4 REM === The Access2Base library is a part of the LibreOffice project. ===
5 REM === Full documentation is available on http://www.access2base.com ===
6 REM =======================================================================================================================
10 Global _A2B_ As Variant
12 REM -----------------------------------------------------------------------------------------------------------------------
13 REM --- PRIVATE FUNCTIONS ---
14 REM -----------------------------------------------------------------------------------------------------------------------
16 Public Function _AddNumeric(ByVal Optional pvTypes As Variant) As Variant
17 'Return on top of argument the list of all numeric types
18 'Facilitates the entry of the list of allowed types in _CheckArgument calls
20 Dim i As Integer, vNewList() As Variant, vNumeric() As Variant, iSize As Integer
21 If IsMissing(pvTypes) Then
23 ElseIf IsArray(pvTypes) Then
26 vNewList = Array(pvTypes)
29 vNumeric = Array(vbInteger, vbLong, vbSingle, vbDouble, vbCurrency, vbBigint, vbDecimal)
31 iSize = UBound(vNewlist)
32 ReDim Preserve vNewList(iSize + UBound(vNumeric) +
1)
33 For i =
0 To UBound(vNumeric)
34 vNewList(iSize + i +
1) = vNumeric(i)
37 _AddNumeric = vNewList
39 End Function
' _AddNumeric V0.8
.0
41 REM -----------------------------------------------------------------------------------------------------------------------
43 Public Function _BitShift(piValue As Integer, piConstant As Integer) As Boolean
46 If piValue =
0 Then Exit Function
47 Select Case piConstant
50 Case
1,
3,
5,
7,
9,
11,
13,
15: _BitShift = True
55 Case
2,
3,
6,
7,
10,
11,
14,
15: _BitShift = True
60 Case
4,
5,
6,
7,
12,
13,
14,
15: _BitShift = True
65 Case
8,
9,
10,
11,
12,
13,
14,
15: _BitShift = True
70 End Function
' BitShift
72 REM -----------------------------------------------------------------------------------------------------------------------
73 Public Function _CalledSub() As String
74 _CalledSub = Iif(_A2B_.CalledSub =
"",
"", _GetLabel(
"CALLTO
")
& " '" & _A2B_.CalledSub
& "'")
75 End Function
' CalledSub V0.8
.9
78 REM -----------------------------------------------------------------------------------------------------------------------
79 Public Function _CheckArgument(pvItem As Variant _
80 , ByVal piArgNr As Integer _
81 , Byval pvType As Variant _
82 , ByVal Optional pvValid As Variant _
83 , ByVal Optional pvError As Boolean _
85 ' Called by public functions to check the validity of their arguments
86 ' pvItem Argument to be checked
87 ' piArgNr Argument sequence number
88 ' pvType Single value or array of allowed variable types
89 ' If of string type must contain one or more valid pseudo-object types
90 ' pvValid Single value or array of allowed values - comparison for strings is case-insensitive
91 ' pvError If True (default), error handling in this routine. False in _setProperty methods in class modules.
93 _CheckArgument = False
95 Dim iVarType As Integer
96 If IsArray(pvType) Then iVarType = VarType(pvType(LBound(pvType))) Else iVarType = VarType(pvType)
97 If iVarType = vbString Then
' pvType is a pseudo-type string
98 _CheckArgument = Utils._IsPseudo(pvItem, pvType)
100 If IsMissing(pvValid) Then _CheckArgument = Utils._IsScalar(pvItem, pvType) Else _CheckArgument = Utils._IsScalar(pvItem, pvType, pvValid)
103 If VarType(pvItem) = vbCurrency Or VarType(pvItem) = vbDecimal Or VarType(pvItem) = vbBigint Then pvItem = CDbl(pvItem)
106 Const cstObject =
"[com.sun.star.script.NativeObjectWrapper]
"
107 If Not _CheckArgument Then
108 If IsMissing(pvError) Then pvError = True
110 TraceError(TRACEFATAL, ERRWRONGARGUMENT, Utils._CalledSub(),
0,
1, Array(piArgNr, pvItem))
114 End Function
' CheckArgument V0.9
.0
116 REM -----------------------------------------------------------------------------------------------------------------------
117 Public Function _CStr(pvArg As Variant, ByVal Optional pbShort As Boolean) As String
118 ' Convert pvArg into a readable string (truncated if too long and pbShort = True or missing)
120 Dim sArg As String, sObject As String, oArg As Object, sLength As String
122 If IsArray(pvArg) Then
123 sArg =
"[ARRAY]
"
125 Select Case VarType(pvArg)
126 Case vbEmpty : sArg =
"[EMPTY]
"
127 Case vbNull : sArg =
"[NULL]
"
129 If IsNull(pvArg) Then
130 sArg =
"[NULL]
"
132 sObject = Utils._ImplementationName(pvArg)
133 If Utils._IsPseudo(pvArg, Array(OBJDATABASE, OBJCOLLECTION, OBJPROPERTY, OBJFORM, OBJSUBFORM, OBJCONTROL, OBJOPTIONGROUP _
134 , OBJEVENT, OBJFIELD, OBJTABLEDEF, OBJQUERYDEF, OBJRECORDSET _
136 Set oArg = pvArg
' To avoid
"Object variable not set
" error message
137 sArg =
"[
" & oArg._Type
& "]
" & oArg._Name
138 ElseIf sObject
<> "" Then
139 sArg =
"[
" & sObject
& "]
"
141 sArg =
"[OBJECT]
"
144 Case vbVariant : sArg =
"[VARIANT]
"
145 Case vbString : sArg = pvArg
146 Case vbBoolean : sArg = Iif(pvArg,
"TRUE
",
"FALSE
")
147 Case Else : sArg = CStr(pvArg)
150 If IsMissing(pbShort) Then pbShort = True
151 If pbShort And Len(sArg)
> cstLength Then
152 sLength =
"(
" & Len(sArg)
& ")
"
153 sArg = Left(sArg, cstLength -
5 - Len(slength))
& " ...
" & sLength
157 End Function
' CStr V0.9
.5
159 REM -----------------------------------------------------------------------------------------------------------------------
160 Public Function _DecimalPoint() As String
161 'Return locale decimal point
162 _DecimalPoint = Mid(Format(
0,
"0.0"),
2,
1)
165 REM -----------------------------------------------------------------------------------------------------------------------
166 Private Function _ExtensionLocation() As String
167 ' Return the URL pointing to the location where OO installed the Access2Base extension
168 ' Adapted from http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Extensions/Location_of_Installed_Extensions
170 Dim oPip As Object, sLocation As String
171 Set oPip = GetDefaultContext.getByName(
"/singletons/com.sun.star.deployment.PackageInformationProvider
")
172 _ExtensionLocation = oPip.getPackageLocation(
"Access2Base
")
174 End Function
' ExtensionLocation
176 REM -----------------------------------------------------------------------------------------------------------------------
177 Private Function _getResultSetColumnValue(poResultSet As Object, Byval piColIndex As Integer) As Variant
178 REM Modified from Roberto Benitez
's BaseTools
179 REM get the data for the column specified by ColIndex
180 REM get type name from metadata
182 Dim vValue As Variant, sType As String, vDateTime As Variant
183 Dim bNullable As Boolean, bNull As Boolean, oValue As Object
185 On Local Error Goto
0 ' Disable error handler
186 vValue = Null
' Default value if error
187 sType = poResultSet.MetaData.getColumnTypeName(piColIndex)
189 bNullable = ( .MetaData.IsNullable(piColIndex) = com.sun.star.sdbc.ColumnValue.NULLABLE )
191 Case
"ARRAY
": vValue = .getArray(piColIndex)
192 Case
"BINARY
",
"VARBINARY
",
"LONGVARBINARY
"
193 Set oValue = .getBinaryStream(piColIndex)
194 If bNullable Then bNull = .wasNull()
195 If Not bNull Then vValue = CLng(oValue.getLength())
' Return length, not content
197 Case
"BLOB
": vValue = .getBlob(piColIndex)
198 Case
"BIT
",
"BOOLEAN
": vValue = .getBoolean(piColIndex)
199 Case
"BYTE
": vValue = .getByte(piColIndex)
200 Case
"BYTES
": vValue = .getBytes(piColIndex)
201 Case
"CLOB
": vValue = .getClob(piColIndex)
202 Case
"DATE
": vDateTime = .getDate(piColIndex)
203 If bNullable Then bNull = .wasNull()
204 If Not bNull Then vValue = DateSerial(CInt(vDateTime.Year), CInt(vDateTime.Month), CInt(vDateTime.Day))
205 Case
"DOUBLE
",
"REAL
": vValue = .getDouble(piColIndex)
206 Case
"FLOAT
": vValue = .getFloat(piColIndex)
207 Case
"INTEGER
",
"SMALLINT
": vValue = .getInt(piColIndex)
208 Case
"LONG
",
"BIGINT
": vValue = .getLong(piColIndex)
209 Case
"DECIMAL
",
"NUMERIC
": vValue = .getDouble(piColIndex)
210 Case
"NULL
": vValue = .getNull(piColIndex)
211 Case
"OBJECT
": vValue = Null
' .getObject(piColIndex) does not work that well in Basic ...
212 Case
"REF
": vValue = .getRef(piColIndex)
213 Case
"SHORT
",
"TINYINT
": vValue = .getShort(piColIndex)
214 Case
"CHAR
",
"VARCHAR
",
"LONGVARCHAR
": vValue = .getString(piColIndex)
215 Case
"TIME
": vDateTime = .getTime(piColIndex)
216 If bNullable Then bNull = .wasNull()
217 If Not bNull Then vValue = TimeSerial(vDateTime.Hours, vDateTime.Minutes, vDateTime.Seconds)
', vDateTime.HundredthSeconds)
218 Case
"TIMESTAMP
": vDateTime = .getTimeStamp(piColIndex)
219 If bNullable Then bNull = .wasNull()
220 If Not bNull Then vValue = DateSerial(CInt(vDateTime.Year), CInt(vDateTime.Month), CInt(vDateTime.Day)) _
221 + TimeSerial(vDateTime.Hours, vDateTime.Minutes, vDateTime.Seconds)
', vDateTime.HundredthSeconds)
223 vValue = .getString(piColIndex)
'GIVE STRING A TRY
224 If IsNumeric(vValue) Then vValue = Val(vValue)
'Required when type =
"", sometimes numeric fields are returned as strings (query/MSAccess)
226 If bNullable Then bNull = .wasNull()
227 If bNull Then vValue = Null
230 _getResultSetColumnValue = vValue
232 End Function
' getResultSetColumnValue V
1.1.0
234 REM -----------------------------------------------------------------------------------------------------------------------
235 Public Function _FinalProperty(psShortcut As String) As String
236 ' Return the final property of a shortcut
238 Const cstEXCLAMATION =
"!
"
239 Const cstDOT =
".
"
241 Dim iCurrentIndex As Integer, vCurrentObject As Variant, sCurrentProperty As String
242 Dim sComponents() As String, sSubComponents() As String
243 _FinalProperty =
""
244 sComponents = Split(Trim(psShortcut), cstEXCLAMATION)
245 If UBound(sComponents) =
0 Then Exit Function
246 sSubComponents = Split(sComponents(UBound(sComponents)), cstDOT)
247 Select Case UBound(sSubComponents)
249 _FinalProperty = sSubComponents(
1)
254 End Function
' FinalProperty
256 REM -----------------------------------------------------------------------------------------------------------------------
257 Public Function _GetProductName(ByVal Optional psFlag As String) as String
258 'Return OO product (
"PRODUCT
") and version numbers (
"VERSION
")
259 'Derived from Tools library
261 Dim oProdNameAccess as Object
262 Dim sVersion as String
263 Dim sProdName as String
264 If IsMissing(psFlag) Then psFlag =
"ALL
"
265 oProdNameAccess = _GetRegistryKeyContent(
"org.openoffice.Setup/Product
")
266 sProdName = oProdNameAccess.getByName(
"ooName
")
267 sVersion = oProdNameAccess.getByName(
"ooSetupVersionAboutBox
")
269 Case
"ALL
" : _GetProductName = sProdName
& " " & sVersion
270 Case
"PRODUCT
" : _GetProductName = sProdName
271 Case
"VERSION
" : _GetProductName = sVersion
273 End Function
' GetProductName V1.0
.0
275 REM -----------------------------------------------------------------------------------------------------------------------
276 Public Function _GetRegistryKeyContent(sKeyName as string, Optional bforUpdate as Boolean) As Variant
277 'Implement ConfigurationProvider service
278 'Derived from Tools library
280 Dim oConfigProvider as Object
281 Dim aNodePath(
0) as new com.sun.star.beans.PropertyValue
282 oConfigProvider = createUnoService(
"com.sun.star.configuration.ConfigurationProvider
")
283 aNodePath(
0).Name =
"nodepath
"
284 aNodePath(
0).Value = sKeyName
285 If IsMissing(bForUpdate) Then bForUpdate = False
287 _GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationUpdateAccess
", aNodePath())
289 _GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments(
"com.sun.star.configuration.ConfigurationAccess
", aNodePath())
291 End Function
' GetRegistryKeyContent V0.8
.5
293 REM -----------------------------------------------------------------------------------------------------------------------
294 Public Function _getUNOTypeName(pvObject As Variant) As String
295 ' Return the symbolic name of the pvObject (UNO-object) type
296 ' Code-snippet from XRAY
298 Dim oService As Object, vClass as Variant
299 _getUNOTypeName =
""
300 On Local Error Resume Next
301 oService = CreateUnoService(
"com.sun.star.reflection.CoreReflection
")
302 vClass = oService.getType(pvObject)
303 If vClass.TypeClass = com.sun.star.uno.TypeClass.STRUCT Then
304 _getUNOTypeName = vClass.Name
308 End Function
' getUNOTypeName
310 REM -----------------------------------------------------------------------------------------------------------------------
311 Public Function _hasUNOMethod(pvObject As Variant, psMethod As String) As Boolean
312 ' Return true if pvObject has the (UNO) method psMethod
313 ' Code-snippet found in Bernard Marcelly
's XRAY
315 Dim vInspect as Variant
316 _hasUNOMethod = False
317 On Local Error Resume Next
318 vInspect = _A2B_.Introspection.Inspect(pvObject)
319 _hasUNOMethod = vInspect.hasMethod(psMethod, com.sun.star.beans.MethodConcept.ALL)
321 End Function
' hasUNOMethod V0.8
.0
323 REM -----------------------------------------------------------------------------------------------------------------------
324 Public Function _hasUNOProperty(pvObject As Variant, psProperty As String) As Boolean
325 ' Return true if pvObject has the (UNO) property psProperty
326 ' Code-snippet found in Bernard Marcelly
's XRAY
328 Dim vInspect as Variant
329 _hasUNOProperty = False
330 On Local Error Resume Next
331 vInspect = _A2B_.Introspection.Inspect(pvObject)
332 _hasUNOProperty = vInspect.hasProperty(psProperty, com.sun.star.beans.PropertyConcept.ALL)
334 End Function
' hasUNOProperty V0.8
.0
336 REM -----------------------------------------------------------------------------------------------------------------------
337 Public Function _ImplementationName(pvObject As Variant) As String
338 ' Use getImplementationName method or _getUNOTypeName function
340 Dim sObjectType As String
341 On Local Error Resume Next
342 sObjectType = pvObject.getImplementationName()
343 If sObjectType =
"" Then sObjectType = _getUNOTypeName(pvObject)
345 _ImplementationName = sObjectType
347 End Function
' ImplementationName
349 REM -----------------------------------------------------------------------------------------------------------------------
350 Public Function _InList(ByVal pvItem As Variant, pvList As Variant, ByVal Optional pvReturnValue As Variant, Optional ByVal pbBinarySearch As Boolean) As Variant
351 ' Return True if pvItem is present in the pvList array (case insensitive comparison)
352 ' Return the value in pvList if pvReturnValue = True
354 Dim i As Integer, bFound As Boolean, iListVarType As Integer, iItemVarType As Integer
355 Dim iTop As Integer, iBottom As Integer, iFound As Integer
356 iItemVarType = VarType(pvItem)
357 If IsMissing(pvReturnValue) Then pvReturnValue = False
358 If iItemVarType = vbNull Or IsNull(pvList) Then
360 ElseIf Not IsArray(pvList) Then
361 If iItemVarType = vbString Then bFound = ( UCase(pvItem) = UCase(pvList) ) Else bFound = ( pvItem = pvList )
362 If Not pvReturnValue Then
365 If bFound Then _InList = pvList Else _InList = False
367 ElseIf UBound(pvList)
< LBound(pvList) Then
' Array not initialized
372 iListVarType = VarType(pvList(LBound(pvList)))
373 If iListVarType = iItemVarType _
374 Or ( (iListVarType = vbInteger Or iListVarType = vbLong Or iListVarType = vbSingle Or iListVarType = vbDouble _
375 Or iListVarType = vbCurrency Or iListVarType = vbBigint Or iListVarType = vbDecimal) _
376 And (iItemVarType = vbInteger Or iItemVarType = vbLong Or iItemVarType = vbSingle Or iItemVarType = vbDouble _
377 Or iItemVarType = vbCurrency Or iItemVarType = vbBigint Or iItemVarType = vbDecimal) _
379 If IsMissing(pbBinarySearch) Then pbBinarySearch = False
380 If Not pbBinarySearch Then
' Linear search
381 For i = LBound(pvList) To UBound(pvList)
382 If iItemVarType = vbString Then bFound = ( UCase(pvItem) = UCase(pvList(i)) ) Else bFound = ( pvItem = pvList(i) )
388 Else
' Binary search =
> array must be sorted
389 iTop = UBound(pvList)
390 iBottom = lBound(pvList)
392 iFound = (iTop + iBottom) /
2
393 If ( iItemVarType = vbString And UCase(pvItem)
> UCase(pvList(iFound)) ) Or ( iItemVarType
<> vbString And pvItem
> pvList(iFound) ) Then
398 If iItemVarType = vbString Then bFound = ( UCase(pvItem) = UCase(pvList(iFound)) ) Else bFound = ( pvItem = pvList(iFound) )
399 Loop Until ( bFound ) Or ( iBottom
> iTop )
402 If Not pvReturnValue Then _InList = True Else _InList = pvList(iFound)
409 End Function
' InList V1.1
.0
411 REM -----------------------------------------------------------------------------------------------------------------------
412 Public Function _InspectPropertyType(poObject As Object, psProperty As String) As String
413 'Return type of property EVEN WHEN EMPTY ! (Used in date and time controls)
415 Dim oInspect1 As Object, oInspect2 As Object, oInspect3 As Object
416 ' On Local Error Resume Next
417 _InspectPropertyType =
""
418 Set oInspect1 = CreateUnoService(
"com.sun.star.script.Invocation
")
419 Set oInspect2 = oInspect1.createInstanceWithArguments(Array(poObject)).IntroSpection
420 If Not IsNull(oInspect2) Then
421 Set oInspect3 = oInspect2.getProperty(psProperty, com.sun.star.beans.PropertyConcept.ALL)
422 If Not IsNull(oInspect3) Then _InspectPropertyType = oInspect3.Type.Name
424 Set oInspect1 = Nothing : Set oInspect2 = Nothing : Set oInspect3 = Nothing
426 End Function
' InspectPropertyType V1.0
.0
428 REM -----------------------------------------------------------------------------------------------------------------------
429 Public Function _IsLeft(psString As String, psLeft As String) As Boolean
430 ' Return True if left part of psString = psLeft
432 Dim iLength As Integer
433 iLength = Len(psLeft)
435 If Len(psString)
>= iLength Then
436 If Left(psString, iLength) = psLeft Then _IsLeft = True
441 REM -----------------------------------------------------------------------------------------------------------------------
442 Public Function _IsPseudo(pvObject As Variant, ByVal pvType As Variant) As Boolean
443 ' Test pvObject: does it exist ?
444 ' is the _Type item = one of the proposed pvTypes ?
445 ' does the pseudo-object refer to an existing object (e.g. does the form really exist in the db) ?
447 Dim bIsPseudo As Boolean, bPseudoExists As Boolean, vObject As Variant
449 If _ErrorHandler() Then On Local Error Goto Exit_False
453 vObject = pvObject
' To avoid
"Object variable not set
" error message
455 Case IsEmpty(vObject)
457 Case VarType(vObject)
<> vbObject
463 Case ._Type =
""
465 bIsPseudo = _InList(._Type, pvType)
466 If Not bIsPseudo Then
' If primary type did not succeed, give the subtype a chance
467 If ._Type = OBJCONTROL Then bIsPseudo = _InList(._SubType, pvType)
473 If Not bIsPseudo Then Goto Exit_Function
475 Dim oDoc As Object, oForms As Variant
477 bPseudoExists = False
481 If ._Name
<> "" Then
' Check validity of form name
482 Set oDoc = _A2B_.CurrentDocument()
483 If oDoc.DbConnect = DBCONNECTFORM Then
486 Set oForms = oDoc.Document.getFormDocuments()
487 bPseudoExists = ( oForms.HasByName(._Name) )
491 If ._DbConnect = DBCONNECTFORM Then bPseudoExists = True Else bPseudoExists = .Document.CurrentController.IsConnected
493 If ._Name
<> "" Then
' Check validity of dialog name
494 bPseudoExists = ( _A2B_.hasItem(COLLALLDIALOGS, ._Name) )
499 If Not IsNull(.ControlModel) And ._Name
<> "" Then
' Check validity of control
500 Set oForms = .ControlModel.Parent
501 bPseudoExists = ( oForms.hasByName(._Name) )
504 If Not IsNull(.DatabaseForm) And ._Name
<> "" Then
' Check validity of subform
505 If .DatabaseForm.ImplementationName =
"com.sun.star.comp.forms.ODatabaseForm
" Then
506 Set oForms = .DatabaseForm.Parent
507 bPseudoExists = ( oForms.hasByName(._Name) )
511 bPseudoExists = ( .Count
> 0 )
513 bPseudoExists = ( Not IsNull(._Window) )
514 Case OBJCOMMANDBARCONTROL
515 bPseudoExists = ( Not IsNull(._ParentCommandBar) )
517 bPseudoExists = ( Not IsNull(._EventSource) )
519 bPseudoExists = ( ._Name
<> "" )
521 bPseudoExists = ( ._Name
<> "" And Not IsNull(.Table) )
523 bPseudoExists = ( ._Name
<> "" And Not IsNull(.Query) )
525 bPseudoExists = ( Not IsNull(.RowSet) )
527 bPseudoExists = ( ._Name
<> "" And Not IsNull(.Column) )
529 If ._Name
<> "" Then
' Check validity of tempvar name
530 bPseudoExists = ( _A2B_.hasItem(COLLTEMPVARS, ._Name) )
536 _IsPseudo = ( bIsPseudo And bPseudoExists )
543 End Function
' IsPseudo V1.1
.0
545 REM -----------------------------------------------------------------------------------------------------------------------
546 Private Function _IsScalar(ByVal pvArg As Variant, Byval pvType As Variant, ByVal Optional pvValid As Variant) As Boolean
547 ' Check type of pvArg and value in allowed pvValid list
551 If IsArray(pvType) Then
552 If Not _InList(VarType(pvArg), pvType) Then Exit Function
553 ElseIf VarType(pvArg)
<> pvType Then
554 If pvType = vbBoolean And VarType(pvArg) = vbLong Then
555 If pvArg
< -
1 And pvArg
> 0 Then Exit Function
' Special boolean processing because the Not function returns a Long
560 If Not IsMissing(pvValid) Then
561 If Not _InList(pvArg, pvValid) Then Exit Function
568 End Function
' IsScalar V0.7
.5
570 REM -----------------------------------------------------------------------------------------------------------------------
571 Public Function _PCase(ByVal psString As String) As String
572 ' Return the proper case representation of argument
574 Dim vSubStrings() As Variant, i As Integer, iLen As Integer
575 vSubStrings = Split(psString,
" ")
576 For i =
0 To UBound(vSubStrings)
577 iLen = Len(vSubStrings(i))
579 vSubStrings(i) = UCase(Left(vSubStrings(i),
1))
& LCase(Right(vSubStrings(i), iLen -
1))
581 vSubStrings(i) = UCase(vSubStrings(i))
584 _PCase = Join(vSubStrings,
" ")
586 End Function
' PCase V0.9
.0
588 REM -----------------------------------------------------------------------------------------------------------------------
589 Public Sub _ResetCalledSub(ByVal psSub As String)
590 ' Called in bottom of each public function. _A2B_.CalledSub variable is used for error handling
591 ' Used to trace routine in/outs and to clarify error messages
592 If IsEmpty(_A2B_) Then Call Application._RootInit()
' Only is Utils module recompiled
593 If _A2B_.CalledSub = psSub Then _A2B_.CalledSub =
""
594 If _A2B_.MinimalTraceLevel =
1 Then TraceLog(TRACEDEBUG, _GetLabel(
"Exiting
")
& " " & psSub
& " ...
", False)
595 End Sub
' ResetCalledSub
597 REM -----------------------------------------------------------------------------------------------------------------------
598 Public Function _RunScript(ByVal psScript As String, Optional pvArgs() As Variant) As Boolean
599 ' Execute a given script with pvArgs() array of arguments
601 On Local Error Goto Error_Function
603 If IsNull(ThisComponent) Then Goto Exit_Function
605 Dim oSCriptProvider As Object, oScript As Object, vResult As Variant
607 Set oScriptProvider = ThisComponent.ScriptProvider()
608 Set oScript = oScriptProvider.getScript(psScript)
609 If IsMissing(pvArgs()) Then pvArgs() = Array()
610 vResult = oScript.Invoke(pvArgs(), Array(), Array())
620 REM -----------------------------------------------------------------------------------------------------------------------
621 Public Sub _SetCalledSub(ByVal psSub As String)
622 ' Called in top of each public function.
623 ' Used to trace routine in/outs and to clarify error messages
624 If IsEmpty(_A2B_) Then Call Application._RootInit()
' First use of Access2Base in current LibO/AOO session
625 If _A2B_.CalledSub =
"" Then _A2B_.CalledSub = psSub
626 If _A2B_.MinimalTraceLevel =
1 Then TraceLog(TRACEDEBUG, _GetLabel(
"Entering
")
& " " & psSub
& " ...
", False)
627 End Sub
' SetCalledSub
629 REM -----------------------------------------------------------------------------------------------------------------------
630 Public Function _Surround(ByVal psName As String) As String
631 ' Return [Name] if Name contains spaces
632 Const cstSquareOpen =
"[
"
633 Const cstSquareClose =
"]
"
634 If InStr(psName,
" ")
> 0 Then
635 _Surround = cstSquareOpen
& psName
& cstSquareClose
639 End Function
' Surround
641 REM -----------------------------------------------------------------------------------------------------------------------
642 Public Function _Trim(ByVal psString As String) As String
643 ' Remove leading and trailing spaces, remove surrounding square brackets
644 Const cstSquareOpen =
"[
"
645 Const cstSquareClose =
"]
"
648 sTrim = Trim(psString)
650 If Len(sTrim)
<=
2 Then Exit Function
652 If Left(sTrim,
1) = cstSquareOpen Then
653 If Right(sTrim,
1) = cstSquareClose Then
654 _Trim = Mid(sTrim,
2, Len(sTrim) -
2)
657 End Function
' Trim V0.9
.0
659 REM -----------------------------------------------------------------------------------------------------------------------
660 Public Function _TrimArray(pvArray As Variant) As Variant
661 ' Remove empty strings from strings array
663 Dim sTrim As String, vTrim() As Variant, i As Integer, j As Integer, iCount As Integer
665 If Not IsArray(pvArray) Then
666 If Len(Trim(pvArray))
> 0 Then vTrim = Array(pvArray) Else vTrim = Array()
667 ElseIf UBound(pvArray)
< LBound(pvArray) Then
' Array empty
671 For i = LBound(pvArray) To UBound(pvArray)
672 If Len(Trim(pvArray(i))) =
0 Then iCount = iCount +
1
676 ElseIf iCount = UBound(pvArray) - LBound(pvArray) +
1 Then
' Array empty or all blanks
679 ReDim vTrim(LBound(pvArray) To UBound(pvArray) - iCount)
681 For i = LBound(pvArray) To UBound(pvArray)
682 If Len(Trim(pvArray(i)))
> 0 Then
683 vTrim(j) = pvArray(i)
690 _TrimArray() = vTrim()
692 End Function
' TrimArray V0.9
.0