diff options
author | Jean-Pierre Ledure <jp@ledure.be> | 2016-12-24 16:27:22 +0100 |
---|---|---|
committer | Jean-Pierre Ledure <jp@ledure.be> | 2017-01-12 11:40:49 +0100 |
commit | 92608b890928b6d10931f4aad3385bb87284181d (patch) | |
tree | 8fc002080d7cb1beee902d7cead925d1aece28a0 /wizards/source | |
parent | 9017bcc76bd27b97c065dacf511f7fcdfe3060cb (diff) |
Access2Base - Addition of Module object
New Module Basic module
New AllModules() collection in Application module
Extension of regex to backward searches
Change-Id: Id58f3b29d08e9f0b73e192cfc0c2a99988e73fcf
Diffstat (limited to 'wizards/source')
-rw-r--r-- | wizards/source/access2base/Application.xba | 160 | ||||
-rw-r--r-- | wizards/source/access2base/Collect.xba | 4 | ||||
-rw-r--r-- | wizards/source/access2base/Dialog.xba | 7 | ||||
-rw-r--r-- | wizards/source/access2base/L10N.xba | 6 | ||||
-rw-r--r-- | wizards/source/access2base/Module.xba | 720 | ||||
-rw-r--r-- | wizards/source/access2base/Root_.xba | 9 | ||||
-rw-r--r-- | wizards/source/access2base/Test.xba | 4 | ||||
-rw-r--r-- | wizards/source/access2base/Utils.xba | 44 | ||||
-rw-r--r-- | wizards/source/access2base/acConstants.xba | 19 | ||||
-rw-r--r-- | wizards/source/access2base/script.xlb | 1 |
10 files changed, 950 insertions, 24 deletions
diff --git a/wizards/source/access2base/Application.xba b/wizards/source/access2base/Application.xba index 19a872007f9f..037d54b5091e 100644 --- a/wizards/source/access2base/Application.xba +++ b/wizards/source/access2base/Application.xba @@ -45,6 +45,7 @@ Global Const ERRSQLSTATEMENT = 1523 Global Const ERROBJECTNOTFOUND = 1524 Global Const ERROPENOBJECT = 1525 Global Const ERRCLOSEOBJECT = 1526 +Global Const ERRMETHOD = 1527 Global Const ERRACTION = 1528 Global Const ERRSENDMAIL = 1529 Global Const ERRFORMYETOPEN = 1530 @@ -74,6 +75,8 @@ Global Const ERRSUBFORMNOTFOUND = 1553 Global Const ERRWINDOW = 1554 Global Const ERRCOMPATIBILITY = 1555 Global Const ERRPRECISION = 1556 +Global Const ERRMODULENOTFOUND = 1557 +Global Const ERRPROCEDURENOTFOUND = 1558 REM ----------------------------------------------------------------------------------------------------------------------- Global Const DBCONNECTBASE = 1 ' Connection from Base document (OpenConnection) @@ -94,6 +97,7 @@ Global Const DBMS_SQLITE = 8 REM ----------------------------------------------------------------------------------------------------------------------- Global Const COLLALLDIALOGS = "ALLDIALOGS" Global Const COLLALLFORMS = "ALLFORMS" +Global Const COLLALLMODULES = "ALLMODULES" Global Const COLLCOMMANDBARS = "COMMANDBARS" Global Const COLLCOMMANDBARCONTROLS = "COMMANDBARCONTROLS" Global Const COLLCONTROLS = "CONTROLS" @@ -116,6 +120,7 @@ Global Const OBJDIALOG = "DIALOG" Global Const OBJEVENT = "EVENT" Global Const OBJFIELD = "FIELD" Global Const OBJFORM = "FORM" +Global Const OBJMODULE = "MODULE" Global Const OBJOPTIONGROUP = "OPTIONGROUP" Global Const OBJPROPERTY = "PROPERTY" Global Const OBJQUERYDEF = "QUERYDEF" @@ -160,6 +165,10 @@ Global Const CTLPARENTISGRID = "GRID" Global Const CTLPARENTISGROUP = "OPTIONGROUP" REM ----------------------------------------------------------------------------------------------------------------------- +Global Const MODDOCUMENT = "DOCUMENT" +Global Const MODGLOBAL = "GLOBAL" + +REM ----------------------------------------------------------------------------------------------------------------------- Type DocContainer Document As Object ' com.sun.star.comp.dba.ODatabaseDocument or SwXTextDocument or ScModelObj Active As Boolean @@ -205,9 +214,11 @@ Const cstSepar = "!" Set oMacLibraries = DialogLibraries vMacLibraries = oMacLibraries.getElementNames() 'Remove Access2Base from the list - For i = 0 To UBound(vMacLibraries) - If Left(vMacLibraries(i), 11) = "Access2Base" Then vMacLibraries(i) = "" - Next i + If _A2B_.ExcludeA2B Then + For i = 0 To UBound(vMacLibraries) + If Left(vMacLibraries(i), 11) = "Access2Base" Then vMacLibraries(i) = "" + Next i + End If vMacLibraries = Utils._TrimArray(vMacLibraries) If UBound(vDocLibraries) + UBound(vMacLibraries) < 0 Then ' No library @@ -394,6 +405,149 @@ Error_Function: End Function ' AllForms V0.9.0 REM ----------------------------------------------------------------------------------------------------------------------- +Public Function AllModules(ByVal Optional pvIndex As Variant, ByVal Optional pbAllModules As Boolean) As Variant +' Return either a Collection or a Module object +' The modules are selected only if library is loaded +' (UNPUBLISHED) pbAllModules = False collects only the modules located in the currently open document + + If _ErrorHandler() Then On Local Error Goto Error_Function +Const cstThisSub = "AllModules" + Utils._SetCalledSub(cstThisSub) + +Dim iMode As Integer, vModules() As Variant, i As Integer, j As Integer, iCount As Integer +Dim oMacLibraries As Object, vAllModules As Variant, oLibrary As Object, vNames() As Variant, bFound As Boolean +Dim sScript As String, sLibrary As String, oDocLibraries As Object, sStorage As String +Dim vLibraries() As Variant, vMacLibraries() As Variant, vDocLibraries() As Variant, oDocMacLib As Object +Const cstCount = 0, cstByIndex = 1, cstByName = 2 +Const cstDot = "." + + If IsMissing(pvIndex) Then + iMode = cstCount + Else + If Not Utils._CheckArgument(pvIndex, 1, Utils._AddNumeric(vbString)) Then Goto Exit_Function + If VarType(pvIndex) = vbString Then + iMode = cstByName + ' Dtermine full name STORAGE.LIBRARY.MODULE + vNames = Split(pvIndex, cstDot) + If UBound(vNames) = 2 Then + ElseIf UBound(vNames) = 1 Then + pvIndex = MODDOCUMENT & cstDot & pvIndex + ElseIf UBound(vNames) = 0 Then + pvIndex = MODDOCUMENT & cstDot & "STANDARD" & cstDot & pvIndex + Else + GoTo Trace_Not_Found + End If + Else + iMode = cstByIndex + End If + End If + + If IsMissing(pbAllModules) Then pbAllModules = True + If Not Utils._CheckArgument(pbAllModules, 2, vbBoolean) Then Goto Exit_Function + + Set vAllModules = Nothing + + Set oDocLibraries = ThisComponent.BasicLibraries + vDocLibraries = oDocLibraries.getElementNames() + If pbAllModules Then + Set oMacLibraries = GlobalScope.BasicLibraries + vMacLibraries = oMacLibraries.getElementNames() + 'Remove Access2Base from the list + If _A2B_.ExcludeA2B Then + For i = 0 To UBound(vMacLibraries) + If Left(vMacLibraries(i), 11) = "Access2Base" Then vMacLibraries(i) = "" + Next i + End If + vMacLibraries = Utils._TrimArray(vMacLibraries) + End If + + If UBound(vDocLibraries) + UBound(vMacLibraries) < 0 Then ' No library + Set vAllModules = New Collect + vAllModules._CollType = COLLALLMODULES + vAllModules._ParentType = OBJAPPLICATION + vAllModules._ParentName = "" + vAllModules._Count = 0 + Goto Exit_Function + End If + + iCount = 0 + For i = 0 To UBound(vDocLibraries) + UBound(vMacLibraries) + 1 + bFound = False + If i <= UBound(vDocLibraries) Then + sLibrary = vDocLibraries(i) + sStorage = MODDOCUMENT + Set oDocMacLib = oDocLibraries + ' Sometimes library not loaded as should ?? + If Not oDocMacLib.IsLibraryLoaded(sLibrary) Then oDocMacLib.loadLibrary(sLibrary) + Else + sLibrary = vMacLibraries(i - UBound(vDocLibraries) - 1) + sStorage = MODGLOBAL + Set oDocMacLib = oMacLibraries + End If + If oDocMacLib.IsLibraryLoaded(sLibrary) Then + Set oLibrary = oDocMacLib.getByName(sLibrary) + If oLibrary.hasElements() Then + vModules = oLibrary.getElementNames() + Select Case iMode + Case cstCount + iCount = iCount + UBound(vModules) + 1 + Case cstByIndex, cstByName + For j = 0 To UBound(vModules) + If iMode = cstByIndex Then + If pvIndex = iCount Then bFound = True + iCount = iCount + 1 + Else + If UCase(pvIndex) = UCase(sStorage & cstDot & sLibrary & cstDot & vModules(j)) Then bFound = True + End If + If bFound Then + sScript = oLibrary.getByName(vModules(j)) ' Initiate Module object + iCount = i + Exit For + End If + Next j + End Select + End If + End If + If bFound Then Exit For + Next i + + If iMode = cstCount Then + Set vAllModules = New Collect + vAllModules._CollType = COLLALLMODULES + vAllModules._ParentType = OBJAPPLICATION + vAllModules._ParentName = "" + vAllModules._Count = iCount + Else + If Not bFound Then + If iMode = cstByIndex Then Goto Trace_Error_Index Else Goto Trace_Not_Found + End If + Set vAllModules = New Module + vAllModules._Name = vModules(j) + vAllModules._LibraryName = sLibrary + Set vAllModules._Library = oLibrary + vAllModules._Storage = sStorage + vAllModules._Script = sScript + vAllModules._Initialize() + End If + +Exit_Function: + Set AllModules = vAllModules + Utils._ResetCalledSub(cstThisSub) + Exit Function +Trace_Not_Found: + TraceError(TRACEFATAL, ERRMODULENOTFOUND, Utils._CalledSub(), 0, , pvIndex) + Goto Exit_Function +Trace_Error_Index: + TraceError(TRACEFATAL, ERRCOLLECTION, Utils._CalledSub(), 0, 1) + Set vModules = Nothing + Goto Exit_Function +Error_Function: + TraceError(TRACEABORT, Err, cstThisSub, Erl) + Set vModules = Nothing + GoTo Exit_Function +End Function ' AllModules V1.7.0 + +REM ----------------------------------------------------------------------------------------------------------------------- Public Sub CloseConnection () ' Close all connections established by current document to free memory. diff --git a/wizards/source/access2base/Collect.xba b/wizards/source/access2base/Collect.xba index ad33cc77a810..d0adbe0a52c4 100644 --- a/wizards/source/access2base/Collect.xba +++ b/wizards/source/access2base/Collect.xba @@ -10,7 +10,7 @@ Option ClassModule Option Explicit -REM MODULE NAME <> COLLECTION (seems a reserved name ?) +REM MODULE NAME <> COLLECTION (is a reserved name for ... collections) REM ----------------------------------------------------------------------------------------------------------------------- REM --- CLASS ROOT FIELDS --- @@ -77,6 +77,8 @@ Dim vNames() As Variant, oProperty As Object Set Item = Application.AllDialogs(pvItem) Case COLLALLFORMS Set Item = Application.AllForms(pvItem) + Case COLLALLMODULES + Set Item = Application.AllModules(pvItem) Case COLLCOMMANDBARS Set Item = Application.CommandBars(pvItem) Case COLLCOMMANDBARCONTROLS diff --git a/wizards/source/access2base/Dialog.xba b/wizards/source/access2base/Dialog.xba index 9d633cda14cb..0fafbd9daaa9 100644 --- a/wizards/source/access2base/Dialog.xba +++ b/wizards/source/access2base/Dialog.xba @@ -14,7 +14,7 @@ REM ---------------------------------------------------------------------------- REM --- CLASS ROOT FIELDS --- REM ----------------------------------------------------------------------------------------------------------------------- -Private _Type As String ' Must be FORM +Private _Type As String ' Must be DIALOG Private _Name As String Private _Shortcut As String Private _Dialog As Object ' com.sun.star.io.XInputStreamProvider @@ -199,7 +199,11 @@ Public Function Properties(ByVal Optional pvIndex As Variant) As Variant ' a Collection object if pvIndex absent ' a Property object otherwise +Const cstThisSub = "Dialog.Properties" + Utils._SetCalledSub(cstThisSub) + Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String + vPropertiesList = _PropertiesList() sObject = Utils._PCase(_Type) If IsMissing(pvIndex) Then @@ -211,6 +215,7 @@ Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String Exit_Function: Set Properties = vProperty + Utils._ResetCalledSub(cstThisSub) Exit Function End Function ' Properties diff --git a/wizards/source/access2base/L10N.xba b/wizards/source/access2base/L10N.xba index 77827795963f..f6e6d8fb2a82 100644 --- a/wizards/source/access2base/L10N.xba +++ b/wizards/source/access2base/L10N.xba @@ -80,6 +80,8 @@ Dim sLocal As String Case "ERR" & ERRWINDOW : sLocal = "Current window is not a document" Case "ERR" & ERRCOMPATIBILITY : sLocal = "Field '%0' could not be converted due to incompatibility of field types between the respective database systems" Case "ERR" & ERRPRECISION : sLocal = "Field '%0' could not be loaded in record #%1 due to capacity shortage" + Case "ERR" & ERRMODULENOTFOUND : sLocal = "Module '%0' not found in the currently loaded libraries" + Case "ERR" & ERRPROCEDURENOTFOUND : sLocal = "Procedure '%0' not found in module '%1'" '---------------------------------------------------------------------------------------------------------------------- Case "OBJECT" : sLocal = "Object" Case "TABLE" : sLocal = "Table" @@ -191,6 +193,8 @@ Dim sLocal As String Case "ERR" & ERRWINDOW : sLocal = "La fenêtre courante n'est pas un document" Case "ERR" & ERRCOMPATIBILITY : sLocal = "Le champ '%0' n'a pas pu être converti à cause d'une incompatibilité entre les types de champs supportés par les systèmes de bases de données respectifs" Case "ERR" & ERRPRECISION : sLocal = "Le champ '%0' n'a pas pu être chargé dans l'enregistrement #%1 par manque de capacité" + Case "ERR" & ERRMODULENOTFOUND : sLocal = "Le module '%0' est introuvable dans les librairies chargées actuellement" + Case "ERR" & ERRPROCEDURENOTFOUND : sLocal = "La procédure '%0' est introuvable dans le module '%1'" '---------------------------------------------------------------------------------------------------------------------- Case "OBJECT" : sLocal = "Objet" Case "TABLE" : sLocal = "Table" @@ -305,6 +309,8 @@ Dim sLocal As String Case "ERR" & ERRWINDOW : sLocal = "La ventana actual no es un documento" Case "ERR" & ERRCOMPATIBILITY : sLocal = "El campo '%0' no se ha convertido debido a una incompatibilidad de los tipos de campo soportados entre las dos bases de datos" Case "ERR" & ERRPRECISION : sLocal = "El campo '%0' no se ha cargado en el registro #%1 por falta de capacidad" + Case "ERR" & ERRMODULENOTFOUND : sLocal = "Module '%0' not found in the currently loaded libraries" + Case "ERR" & ERRPROCEDURENOTFOUND : sLocal = "Procedure '%0' not found in module '%1'" '---------------------------------------------------------------------------------------------------------------------- Case "OBJECT" : sLocal = "Objeto" Case "TABLE" : sLocal = "Tabla" diff --git a/wizards/source/access2base/Module.xba b/wizards/source/access2base/Module.xba new file mode 100644 index 000000000000..64eea2f102c9 --- /dev/null +++ b/wizards/source/access2base/Module.xba @@ -0,0 +1,720 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> +<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module" script:language="StarBasic">REM ======================================================================================================================= +REM === The Access2Base library is a part of the LibreOffice project. === +REM === Full documentation is available on http://www.access2base.com === +REM ======================================================================================================================= + +Option Compatible +Option ClassModule + +Option Explicit + +REM ----------------------------------------------------------------------------------------------------------------------- +REM --- CLASS ROOT FIELDS --- +REM ----------------------------------------------------------------------------------------------------------------------- + +Private _Type As String ' Must be MODULE +Private _Name As String +Private _Library As Object ' com.sun.star.container.XNameAccess +Private _LibraryName As String +Private _Storage As String ' GLOBAL or DOCUMENT +Private _Script As String ' Full script (string with vbLf's) +Private _Lines As Variant ' Array of script lines +Private _CountOfLines As Long +Private _ProcsParsed As Boolean ' To test before use of proc arrays +Private _ProcNames() As Variant ' All procedure names +Private _ProcDecPositions() As Variant ' All procedure declarations +Private _ProcEndPositions() As Variant ' All end procedure statements +Private _ProcTypes() As Variant ' One of the vbext_pk_* constants + +REM ----------------------------------------------------------------------------------------------------------------------- +REM --- CONSTRUCTORS / DESTRUCTORS --- +REM ----------------------------------------------------------------------------------------------------------------------- +Private Sub Class_Initialize() + _Type = OBJMODULE + _Name = "" + Set _Library = Nothing + _LibraryName = "" + _Storage = "" + _Script = "" + _Lines = Array() + _CountOfLines = 0 + _ProcsParsed = False + _ProcNames = Array() + _ProcDecPositions = Array() + _ProcEndPositions = Array() +End Sub ' Constructor + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Sub Class_Terminate() + On Local Error Resume Next + Call Class_Initialize() +End Sub ' Destructor + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Sub Dispose() + Call Class_Terminate() +End Sub ' Explicit destructor + +REM ----------------------------------------------------------------------------------------------------------------------- +REM --- CLASS GET/LET/SET PROPERTIES --- +REM ----------------------------------------------------------------------------------------------------------------------- + +REM ----------------------------------------------------------------------------------------------------------------------- +Property Get CountOfDeclarationLines() As Long + CountOfDeclarationLines = _PropertyGet("CountOfDeclarationLines") +End Property ' CountOfDeclarationLines (get) + +REM ----------------------------------------------------------------------------------------------------------------------- +Property Get CountOfLines() As Long + CountOfLines = _PropertyGet("CountOfLines") +End Property ' CountOfLines (get) + +REM ----------------------------------------------------------------------------------------------------------------------- +Property Get Name() As String + Name = _PropertyGet("Name") +End Property ' Name (get) + +REM ----------------------------------------------------------------------------------------------------------------------- +Property Get ObjectType() As String + ObjectType = _PropertyGet("ObjectType") +End Property ' ObjectType (get) + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function Lines(Optional ByVal pvLine As Variant, Optional ByVal pvNumLines As Variant) As String +' Returns a string containing the contents of a specified line or lines in a standard module or a class module + +Const cstThisSub = "Module.Lines" + Utils._SetCalledSub(cstThisSub) + +Dim sLines As String, lLine As Long + sLines = "" + + If IsMissing(pvLine) Or IsMissing(pvNumLines) Then Call _TraceArguments() + If Not Utils._CheckArgument(pvLine, 1, _AddNumeric()) Then GoTo Exit_Function + If Not Utils._CheckArgument(pvNumLines, 1, _AddNumeric()) Then GoTo Exit_Function + + lLine = pvLine + Do While lLine < _CountOfLines And lLine < pvLine + pvNumLines + sLines = sLines & _Lines(lLine - 1) & vbLf + lLine = lLine + 1 + Loop + If Len(sLines) > 0 Then sLines = Left(sLines, Len(sLines) - 1) + +Exit_Function: + Lines = sLines + Utils._ResetCalledSub(cstThisSub) + Exit Function +End Function ' Lines + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function ProcBodyLine(Optional ByVal pvProc As Variant, Optional ByVal pvProcType As Variant) As Long +' Return the number of the line at which the body of a specified procedure begins + +Const cstThisSub = "Module.ProcBodyLine" + Utils._SetCalledSub(cstThisSub) + +Dim iIndex As Integer + + If IsMissing(pvProc) Or IsMissing(pvProcType) Then Call _TraceArguments() + If Not Utils._CheckArgument(pvProc, 1, vbString) Then GoTo Exit_Function + If Not Utils._CheckArgument(pvProcType, 2, _AddNumeric()) Then GoTo Exit_Function + + iIndex = _FindProcIndex(pvProc, pvProcType) + If iIndex >= 0 Then ProcBodyLine = _LineOfPosition(_ProcDecPositions(iIndex)) Else ProcBodyLine = iIndex + +Exit_Function: + Utils._ResetCalledSub(cstThisSub) + Exit Function +End Function ' ProcBodyline + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function ProcCountLines(Optional ByVal pvProc As Variant, Optional ByVal pvProcType As Variant) As Long +' Return the number of lines in the specified procedure + +Const cstThisSub = "Module.ProcCountLines" + Utils._SetCalledSub(cstThisSub) + +Dim iIndex As Integer, lStart As Long, lEnd As Long + + If IsMissing(pvProc) Or IsMissing(pvProcType) Then Call _TraceArguments() + If Not Utils._CheckArgument(pvProc, 1, vbString) Then GoTo Exit_Function + If Not Utils._CheckArgument(pvProcType, 2, _AddNumeric()) Then GoTo Exit_Function + + iIndex = _FindProcIndex(pvProc, pvProcType) + lStart = ProcStartLine(pvProc, pvProcType) + lEnd = _LineOfPosition(_ProcEndPositions(iIndex)) + ProcCountLines = lEnd - lStart + 1 + +Exit_Function: + Utils._ResetCalledSub(cstThisSub) + Exit Function +End Function ' ProcCountLines + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function ProcOfLine(Optional ByVal pvLine As Variant, Optional ByRef pvProcType As Variant) As String +' Return the name and type of the procedure containing line pvLine + +Const cstThisSub = "Module.ProcOfLine" + Utils._SetCalledSub(cstThisSub) + +Dim sProcedure As String, iProc As Integer, lLineDec As Long, lLineEnd As Long + + If IsMissing(pvLine) Or IsMissing(pvProcType) Then Call _TraceArguments() + If Not Utils._CheckArgument(pvLine, 1, _AddNumeric()) Then GoTo Exit_Function + If Not Utils._CheckArgument(pvProcType, 2, _AddNumeric()) Then GoTo Exit_Function + + If Not _ProcsParsed Then _ParseProcs() + + sProcedure = "" + For iProc = 0 To UBound(_ProcNames) + lLineEnd = _LineOfPosition(_ProcEndPositions(iProc)) + If pvLine <= lLineEnd Then + lLineDec = _LineOfPosition(_ProcDecPositions(iProc)) + If pvLine < lLineDec Then ' Line between 2 procedures + sProcedure = "" + Else + sProcedure = _ProcNames(iProc) + pvProcType = _ProcTypes(iProc) + End If + Exit For + End If + Next iProc + +Exit_Function: + ProcOfLine = sProcedure + Utils._ResetCalledSub(cstThisSub) + Exit Function +End Function ' ProcOfline + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function ProcStartLine(Optional ByVal pvProc As Variant, Optional ByVal pvProcType As Variant) As Long +' Return the number of the line at which the specified procedure begins + +Const cstThisSub = "Module.ProcStartLine" + Utils._SetCalledSub(cstThisSub) + +Dim lLine As Long, lIndex As Long, sLine As String + + If IsMissing(pvProc) Or IsMissing(pvProcType) Then Call _TraceArguments() + If Not Utils._CheckArgument(pvProc, 1, vbString) Then GoTo Exit_Function + If Not Utils._CheckArgument(pvProcType, 2, _AddNumeric()) Then GoTo Exit_Function + + lLine = ProcBodyLine(pvProc, pvProcType) + ' Search baclIndexward for comment lines + lIndex = lLine - 1 + Do While lIndex > 0 + sLine = _Trim(_Lines(lIndex - 1)) + If UCase(Left(sLine, 4)) = "REM " Or Left(sLine, 1) = "'" Then + lLine = lIndex + Else + Exit Do + End If + lIndex = lIndex - 1 + Loop + + ProcStartLine = lLine + +Exit_Function: + Utils._ResetCalledSub(cstThisSub) + Exit Function +End Function ' ProcStartLine + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function Properties(ByVal Optional pvIndex As Variant) As Variant +' Return +' a Collection object if pvIndex absent +' a Property object otherwiseREM ----------------------------------------------------------------------------------------------------------------------- + + +Const cstThisSub = "Module.Properties" + Utils._SetCalledSub(cstThisSub) + +Dim vProperty As Variant, vPropertiesList() As Variant, sObject As String + + vPropertiesList = _PropertiesList() + sObject = Utils._PCase(_Type) + If IsMissing(pvIndex) Then + vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList) + Else + vProperty = PropertiesGet._Properties(sObject, _Name, vPropertiesList, pvIndex) + vProperty._Value = _PropertyGet(vPropertiesList(pvIndex)) + End If + +Exit_Function: + Set Properties = vProperty + Utils._ResetCalledSub(cstThisSub) + Exit Function +End Function ' Properties + +REM ----------------------------------------------------------------------------------------------------------------------- +Property Get pType() As String + pType = _PropertyGet("Type") +End Property ' Type (get) + +REM ----------------------------------------------------------------------------------------------------------------------- +REM --- CLASS METHODS --- +REM ----------------------------------------------------------------------------------------------------------------------- + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function Find(Optional ByVal pvTarget As Variant _ + , Optional ByRef pvStartLine As Variant _ + , Optional ByRef pvStartColumn As Variant _ + , Optional ByRef pvEndLine As Variant _ + , Optional ByRef pvEndColumn As Variant _ + , Optional ByVal pvWholeWord As Boolean _ + , Optional ByVal pvMatchCase As Boolean _ + , Optional ByVal pvPatternSearch As Boolean _ + ) As Boolean +' Finds specified text in the module +' xxLine and xxColumn arguments are mainly to return the position of the found string +' If they are initialized but nonsense, the function returns False + +Const cstThisSub = "Module.Find" + Utils._SetCalledSub(cstThisSub) + If _ErrorHandler() Then On Local Error Goto Error_Function + +Dim bFound As Boolean, lPosition As Long, lStartLine As Long, lStartColumn As Long, lStartPosition As Long +Dim lEndLine As Long, lEndColumn As Long, lEndPosition As Long +Dim sMatch As String, vOptions As Variant, sPattern As String +Dim i As Integer, sSpecChar As String + +Const cstSpecialCharacters = "\[^$.|?*+()" + + bFound = False + + If IsMissing(pvTarget) Or IsMissing(pvStartLine) Or IsMissing(pvStartColumn) Or IsMissing(pvEndLine) Or IsMissing(pvEndColumn) Then Call _TraceArguments() + If Not Utils._CheckArgument(pvTarget, 1, vbString) Then GoTo Exit_Function + If Len(pvTarget) = 0 Then GoTo Exit_Function + If Not IsEmpty(pvStartLine) Then + If Not Utils._CheckArgument(pvStartLine, 2, _AddNumeric()) Then GoTo Exit_Function + End If + If Not IsEmpty(pvStartColumn) Then + If Not Utils._CheckArgument(pvStartColumn, 3, _AddNumeric()) Then GoTo Exit_Function + End If + If Not IsEmpty(pvEndLine) Then + If Not Utils._CheckArgument(pvEndLine, 4, _AddNumeric()) Then GoTo Exit_Function + End If + If Not IsEmpty(pvEndColumn) Then + If Not Utils._CheckArgument(pvEndColumn, 5, _AddNumeric()) Then GoTo Exit_Function + End If + If IsMissing(pvWholeWord) Then pvWholeWord = False + If Not Utils._CheckArgument(pvWholeWord, 6, vbBoolean) Then GoTo Exit_Function + If IsMissing(pvMatchCase) Then pvMatchCase = False + If Not Utils._CheckArgument(pvMatchCase, 7, vbBoolean) Then GoTo Exit_Function + If IsMissing(pvPatternSearch) Then pvPatternSearch = False + If Not Utils._CheckArgument(pvPatternSearch, 8, vbBoolean) Then GoTo Exit_Function + + ' Initialize starting values + If IsEmpty(pvStartLine) Then lStartLine = 1 Else lStartLine = pvStartLine + If lStartLine <= 0 Or lStartLine > UBound(_Lines) + 1 Then GoTo Exit_Function + If IsEmpty(pvStartColumn) Then lStartColumn = 1 Else lStartColumn = pvStartColumn + If lStartColumn <= 0 Then GoTo Exit_Function + If lStartColumn > 1 And lStartColumn > Len(_Lines(lStartLine + 1)) Then GoTo Exit_Function + lStartPosition = _PositionOfLine(lStartline) + lStartColumn - 1 + If IsEmpty(pvEndLine) Then lEndLine = UBound(_Lines) + 1 Else lEndLine = pvEndLine + If lEndLine < lStartLine Or lEndLine > UBound(_Lines) + 1 Then GoTo Exit_Function + If IsEmpty(pvEndColumn) Then lEndColumn = Len(_Lines(lEndLine - 1)) Else lEndColumn = pvEndColumn + If lEndColumn < 0 Then GoTo Exit_Function + If lEndColumn = 0 Then lEndColumn = 1 + If lEndColumn > Len(_Lines(lEndLine - 1)) + 1 Then GoTo Exit_Function + lEndPosition = _PositionOfLine(lEndline) + lEndColumn - 1 + + If pvMatchCase Then + Set vOptions = _A2B_.SearchOptions + vOptions.transliterateFlags = 0 + End If + + ' Define pattern to search for + sPattern = pvTarget + ' Protect special characters in regular expressions + For i = 1 To Len(cstSpecialCharacters) + sSpecChar = Mid(cstSpecialCharacters, i, 1) + sPattern = Replace(sPattern, sSpecChar, "\" & sSpecChar) + Next i + If pvPatternSearch Then sPattern = Replace(Replace(sPattern, "\*", ".*"), "\?", ".") + If pvWholeWord Then sPattern = "\b" & sPattern & "\b" + + lPosition = lStartPosition + sMatch = Utils._RegexSearch(_Script, sPattern, lPosition) + ' Re-establish default options for later searches + If pvMatchCase Then vOptions.transliterateFlags = com.sun.star.i18n.TransliterationModules.IGNORE_CASE + + ' Found within requested bounds ? + If sMatch <> "" And lPosition >= lStartPosition And lPosition <= lEndPosition Then + pvStartLine = _LineOfPosition(lPosition) + pvStartColumn = lPosition - _PositionOfLine(pvStartLine) + 1 + pvEndLine = _LineOfPosition(lPosition + Len(sMatch) - 1) + If pvEndLine > pvStartLine Then + pvEndColumn = lPosition + Len(sMatch) - 1 - _PositionOfLine(pvEndLine) + Else + pvEndColumn = pvStartColumn + Len(sMatch) - 1 + End If + bFound = True + End If + +Exit_Function: + Find = bFound + Utils._ResetCalledSub(cstThisSub) + Exit Function +Error_Function: + TraceError(TRACEABORT, Err, "Module.Find", Erl) + bFound = False + GoTo Exit_Function +End Function ' Find + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Function getProperty(Optional ByVal pvProperty As Variant) As Variant +' Return property value of psProperty property nameREM ----------------------------------------------------------------------------------------------------------------------- + + +Const cstThisSub = "Module.Properties" + + Utils._SetCalledSub(cstThisSub) + If IsMissing(pvProperty) Then Call _TraceArguments() + getProperty = _PropertyGet(pvProperty) + Utils._ResetCalledSub(cstThisSub) + +End Function ' getProperty + +REM --------------------------------Mid(a._Script, iCtl, 25)--------------------------------------------------------------------------------------- +Public Function hasProperty(ByVal Optional pvProperty As Variant) As Boolean +' Return True if object has a valid property called pvProperty (case-insensitive comparison !) + +Const cstThisSub = "Module.hasProperty" + + Utils._SetCalledSub(cstThisSub) + If IsMissing(pvProperty) Then hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList()) Else hasProperty = PropertiesGet._hasProperty(_Type, _PropertiesList(), pvProperty) + Utils._ResetCalledSub(cstThisSub) + Exit Function + +End Function ' hasProperty + +REM ----------------------------------------------------------------------------------------------------------------------- +REM --- PRIVATE FUNCTIONS --- +REM ----------------------------------------------------------------------------------------------------------------------- + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _BeginStatement(ByVal plStart As Long) As Long +' Return the position in _Script of the beginning of the current statement as defined by plStart + +Dim sProc As String, iProc As Integer, iType As Integer +Dim lPosition As Long, lPrevious As Long, sFind As String + + sProc = ProcOfLine(_LineOfPosition(plStart), iType) + iProc = _FindProcIndex(sProc, iType) + If iProc < 0 Then lPosition = 1 Else lPosition = _ProcDecPositions(iProc) + + sFind = "Any" + Do While lPosition < plStart And sFind <> "" + lPrevious = lPosition + sFind = _FindPattern("%^\w", lPosition) + If sFind = "" Then Exit Do + Loop + + _BeginStatement = lPrevious + +End Function ' _EndStatement + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _EndStatement(ByVal plStart As Long) As Long +' Return the position in _Script of the end of the current statement as defined by plStart +' plStart is assumed not to be in the middle of a comment or a string + +Dim sMatch As String, lPosition As Long + lPosition = plStart + sMatch = _FindPattern("%$", lPosition) + _EndStatement = lPosition + +End Function ' _EndStatement + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _FindPattern(ByVal psPattern As Variant, Optional ByRef plStart As Long) As String +' Find first occurrence of any of the patterns in |-delimited string psPattern +' Special escapes +' - for word breaks: "%B" (f.i. for searching "END%BFUNCTION") +' - for statement start: "%^" (f.i. for searching "%^END%BFUNCTION"). Necessarily first 2 characters of pattern +' - for statement end: "%$". Pattern should not contain anything else +' If quoted string searched, pattern should start and end with a double quote +' Return "" if none found, otherwise returns the matching string +' plStart = start position of _Script to search (starts at 1) +' In output plStart contains the first position of the matching string or is left unchanged +' To search again the same or another pattern => plStart = plStart + Len(matching string) +' Comments and strings are skipped + +' Common patterns +Const cstComment = "('|\bREM\b)[^\n]*$" +Const cstString = """[^""]*""" +Const cstBeginStatement = "(^|:|\bthen\b|\belse\b|\n)[ \t]*" +Const cstEndStatement = "[ \t]*($|:|\bthen\b|\belse\b|\n)" +Const cstContinuation = "[ \t]_\n" +Const cstWordBreak = "\b[ \t]+(_\n[ \t]*)?\b" +Const cstAlt = "|" + +Dim sRegex As String, lStart As Long, bContinue As Boolean, sMatch As String +Dim bEndStatement As Boolean, bQuote As Boolean + + If psPattern = "%$" Then + sRegex = cstEndStatement + Else + sRegex = psPattern + If Left(psPattern, 2) = "%^" Then sRegex = cstBeginStatement & Right(sRegex, Len(sregex) - 2) + sregex = Replace(sregex, "%B", cstWordBreak) + End If + ' Add all to ignore patterns to regex. If pattern = quoted string do not add cstString + If Len(psPattern) > 2 And Left(psPattern, 1) = """" And Right(psPattern, 1) = """" Then + bQuote = True + sRegex = sRegex & cstAlt & cstComment & cstAlt & cstContinuation + Else + bQuote = False + sRegex = sRegex & cstAlt & cstComment & cstAlt & cstString & cstAlt & cstContinuation + End If + + If IsMissing(plStart) Then plStart = 1 + lStart = plStart + + bContinue = True + Do While bContinue + bEndStatement = False + sMatch = Utils._RegexSearch(_Script, sRegex, lStart) + Select Case True + Case sMatch = "" + bContinue = False + Case Left(sMatch, 1) = "'" + bEndStatement = True + Case Left(sMatch, 1) = """" + If bQuote Then + plStart = lStart + bContinue = False + End If + Case Left(smatch, 1) = ":" Or Left(sMatch, 1) = vbLf + If psPattern = "%$" Then + bEndStatement = True + Else + bContinue = False + plStart = lStart + 1 + sMatch = Right(sMatch, Len(sMatch) - 1) + End If + Case UCase(Left(sMatch, 3)) = "REM" + bEndStatement = True + Case UCase(Left(sMatch, 4)) = "THEN" Or UCase(Left(sMatch, 4)) = "ELSE" + If psPattern = "%$" Then + bEndStatement = True + Else + bContinue = False + plStart = lStart + 4 + sMatch = Right(sMatch, Len(sMatch) - 4) + End If + Case sMatch = " _" & vbLf + Case Else ' Found + plStart = lStart + bContinue = False + End Select + If bEndStatement And psPattern = "%$" Then + bContinue = False + plStart = lStart - 1 + sMatch = "" + End If + lStart = lStart + Len(sMatch) + Loop + + _FindPattern = sMatch + +End Function ' _FindPattern + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _FindProcIndex(ByVal psProc As String, ByVal piType As Integer) As Integer +' Return index of entry in _Procnames corresponding with pvProc + +Dim i As Integer, iIndex As Integer + + If Not _ProcsParsed Then _ParseProcs + + iIndex = -1 + For i = 0 To UBound(_ProcNames) + If UCase(psProc) = UCase(_ProcNames(i)) And piType = _ProcTypes(i) Then + iIndex = i + Exit For + End If + Next i + If iIndex < 0 Then TraceError(TRACEFATAL, ERRPROCEDURENOTFOUND, Utils._CalledSub(), 0, , Array(psProc, _Name)) + +Exit_Function: + _FindProcIndex = iIndex + Exit Function +End Function ' _FindProcIndex + +REM ----------------------------------------------------------------------------------------------------------------------- +Public Sub _Initialize() + + _Script = Replace(_Script, vbCr, "") + _Lines = Split(_Script, vbLf) + _CountOfLines = UBound(_Lines) + 1 + +End Sub ' _Initialize + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _LineOfPosition(ByVal plPosition) As Long +' Return the line number of a position in _Script + +Dim lLine As Long, lLength As Long + ' Start counting from start or end depending on how close position is + If plPosition <= Len(_Script) / 2 Then + lLength = 0 + For lLine = 0 To UBound(_Lines) + lLength = lLength + Len(_Lines(lLine)) + 1 ' + 1 for line feed + If lLength >= plPosition Then + _LineOfPosition = lLine + 1 + Exit Function + End If + Next lLine + Else + If Right(_Script, 1) = vbLf Then lLength = Len(_Script) + 1 Else lLength = Len(_Script) + For lLine = UBound(_Lines) To 0 Step -1 + lLength = lLength - Len(_Lines(lLine)) - 1 ' - 1 for line feed + If lLength <= plPosition Then + _LineOfPosition = lLine + 1 + Exit Function + End If + Next lLine + End If + +End Function ' _LineOfPosition + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Sub _ParseProcs() +' Fills the Proc arrays: name, start and end position +' Executed at first request needing this processing + +Dim lPosition As Long, iProc As Integer, sDecProc As String, sEndProc As String, sNameProc As String, sType As String +Const cstDeclaration = "%^(private%B|public%B)?\b(property%Bget|property%Blet|property%Bset|function|sub)\b" +Const cstEnd = "%^end%B(property|function|sub)\b" +Const cstName = "\w*" '"[A-Za-z_][A-Za-z_0-9]*" + + If _ProcsParsed Then Exit Sub ' Do not redo if already done + _ProcNames = Array() + _ProcDecPositions = Array() + _ProcEndPositions = Array() + _ProcTypes = Array() + + lPosition = 1 + iProc = -1 + sDecProc = "???" + Do While sDecProc <> "" + ' Identify Function/Sub declaration string + sDecProc = _FindPattern(cstDeclaration, lPosition) + If sDecProc <> "" Then + iProc = iProc + 1 + ReDim Preserve _ProcNames(0 To iProc) + ReDim Preserve _ProcDecPositions(0 To iProc) + ReDim Preserve _ProcEndPositions(0 To iProc) + ReDim Preserve _ProcTypes(0 To iProc) + _ProcDecpositions(iProc) = lPosition + lPosition = lPosition + Len(sDecProc) + ' Identify procedure type + Select Case True + Case InStr(UCase(sDecProc), "FUNCTION") > 0 : _ProcTypes(iProc) = vbext_pk_Proc + Case InStr(UCase(sDecProc), "SUB") > 0 : _ProcTypes(iProc) = vbext_pk_Proc + Case InStr(UCase(sDecProc), "GET") > 0 : _ProcTypes(iProc) = vbext_pk_Get + Case InStr(UCase(sDecProc), "LET") > 0 : _ProcTypes(iProc) = vbext_pk_Let + Case InStr(UCase(sDecProc), "SET") > 0 : _ProcTypes(iProc) = vbext_pk_Set + End Select + ' Identify name of Function/Sub + sNameProc = _FindPattern(cstName, lPosition) + If sNameProc = "" Then Exit Do ' Should never happen + _ProcNames(iProc) = sNameProc + lPosition = lPosition + Len(sNameProc) + ' Identify End statement + sEndProc = _FindPattern(cstEnd, lPosition) + If sEndProc = "" Then Exit Do ' Should never happen + _ProcEndPositions(iProc) = lPosition + lPosition = lPosition + Len(sEndProc) + End If + Loop + + _ProcsParsed = True + +End Sub + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _PositionOfLine(ByVal plLine) As Long +' Return the position of the first character of the given line in _Script + +Dim lLine As Long, lPosition As Long + ' Start counting from start or end depending on how close line is + If plLine <= (UBound(_Lines) + 1) / 2 Then + lPosition = 0 + For lLine = 0 To plLine - 1 + lPosition = lPosition + 1 ' + 1 for line feed + If lLine < plLine - 1 Then lPosition = lPosition + Len(_Lines(lLine)) + Next lLine + Else + lPosition = Len(_Script) + 2 ' Anticipate an ending null-string and a line feed + For lLine = UBound(_Lines) To plLine - 1 Step -1 + lPosition = lPosition - Len(_Lines(lLine)) - 1 ' - 1 for line feed + Next lLine + End If + + _PositionOfLine = lPosition + +End Function ' _LineOfPosition + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _PropertiesList() As Variant + + _PropertiesList = Array("CountOfDeclarationLines", "CountOfLines", "Name", "ObjectType", "Type") + +End Function ' _PropertiesList + +REM ----------------------------------------------------------------------------------------------------------------------- +Private Function _PropertyGet(ByVal psProperty As String) As Variant +' Return property value of the psProperty property name + +Dim cstThisSub As String +Const cstDot = "." + +Dim sText As String + + If _ErrorHandler() Then On Local Error Goto Error_Function + cstThisSub = "Module.get" & psProperty + Utils._SetCalledSub(cstThisSub) + _PropertyGet = Null + + Select Case UCase(psProperty) + Case UCase("CountOfDeclarationLines") + If Not _ProcsParsed Then _ParseProcs() + If UBound(_ProcNames) >= 0 Then + _PropertyGet = ProcStartLine(_ProcNames(0), _ProcTypes(0)) - 1 + Else + _PropertyGet = _CountOfLines + End If + Case UCase("CountOfLines") + _PropertyGet = _CountOfLines + Case UCase("Name") + _PropertyGet = _Storage & cstDot & _LibraryName & cstDot & _Name + Case UCase("ObjectType") + _PropertyGet = _Type + Case UCase("Type") + ' Find option statement before any procedure declaration + sText = _FindPattern("%^option%Bclassmodule\b|\bfunction\b|\bsub\b|\bproperty\b") + If UCase(Left(sText, 6)) = "OPTION" Then _PropertyGet = acClassModule Else _PropertyGet = acStandardModule + Case Else + Goto Trace_Error + End Select + +Exit_Function: + Utils._ResetCalledSub(cstThisSub) + Exit Function +Trace_Error: + TraceError(TRACEFATAL, ERRPROPERTY, Utils._CalledSub(), 0, 1, psProperty) + _PropertyGet = Nothing + Goto Exit_Function +Error_Function: + TraceError(TRACEABORT, Err, "Module._PropertyGet", Erl) + _PropertyGet = Null + GoTo Exit_Function +End Function ' _PropertyGet + + +</script:module>
\ No newline at end of file diff --git a/wizards/source/access2base/Root_.xba b/wizards/source/access2base/Root_.xba index 42475c927d70..01f50923b6cd 100644 --- a/wizards/source/access2base/Root_.xba +++ b/wizards/source/access2base/Root_.xba @@ -29,7 +29,9 @@ Private DebugPrintShort As Boolean Private Introspection As Object ' com.sun.star.beans.Introspection Private VersionNumber As String ' Actual Access2Base version number Private Locale As String +Private ExcludeA2B As Boolean Private TextSearch As Object +Private SearchOptions As Variant Private FindRecord As Object Private StatusBar As Object Private Dialogs As Object ' Collection @@ -51,8 +53,15 @@ Dim vCurrentDoc() As Variant CalledSub = "" DebugPrintShort = True Locale = L10N._GetLocale() + ExcludeA2B = True Set Introspection = CreateUnoService("com.sun.star.beans.Introspection") Set TextSearch = CreateUnoService("com.sun.star.util.TextSearch") + SearchOptions = New com.sun.star.util.SearchOptions + With SearchOptions + .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP + .searchFlag = 0 + .transliterateFlags = com.sun.star.i18n.TransliterationModules.IGNORE_CASE + End With Set FindRecord = Nothing Set StatusBar = Nothing Set Dialogs = New Collection diff --git a/wizards/source/access2base/Test.xba b/wizards/source/access2base/Test.xba index b69d93f36a2c..bada74473061 100644 --- a/wizards/source/access2base/Test.xba +++ b/wizards/source/access2base/Test.xba @@ -4,6 +4,10 @@ 'Option Compatible Sub Main +Dim a, b() + _ErrorHandler(False) + TraceConsole() + exit sub End Sub </script:module>
\ No newline at end of file diff --git a/wizards/source/access2base/Utils.xba b/wizards/source/access2base/Utils.xba index 6028df496253..668507867369 100644 --- a/wizards/source/access2base/Utils.xba +++ b/wizards/source/access2base/Utils.xba @@ -913,9 +913,10 @@ Error_Function: End Function ' _ReadFileIntoArray V1.4.0 REM ----------------------------------------------------------------------------------------------------------------------- -Function _RegexSearch(ByRef psString As String _ +Public Function _RegexSearch(ByRef psString As String _ , ByVal psRegex As String _ , Optional ByRef plStart As Long _ + , Optional ByVal bForward As Boolean _ ) As String ' Search is not case-sensitive ' Return "" if regex not found, otherwise returns the matching string @@ -924,26 +925,35 @@ Function _RegexSearch(ByRef psString As String _ ' To search again the same or another pattern => plStart = plStart + Len(matching string) Dim oTextSearch As Object -Dim vOptions As New com.sun.star.util.SearchOptions, vResult As Object -Dim lEnd As Long +Dim vOptions As Variant 'com.sun.star.util.SearchOptions +Dim lEnd As Long, vResult As Object _RegexSearch = "" Set oTextSearch = _A2B_.TextSearch ' UNO XTextSearch service - With vOptions - .algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP - .searchFlag = 0 - .searchString = psRegex ' Pattern to be searched - .transliterateFlags = com.sun.star.i18n.TransliterationModules.IGNORE_CASE - End With + vOptions = _A2B_.SearchOptions + vOptions.searchString = psRegex ' Pattern to be searched oTextSearch.setOptions(vOptions) If IsMissing(plStart) Then plStart = 1 - If plStart <= 0 Then Exit Function - lEnd = Len(psString) - vResult = oTextSearch.searchForward(psString, plStart - 1, lEnd) + If plStart <= 0 Or plStart > Len(psString) Then Exit Function + If IsMissing(bForWard) Then bForward = True + If bForward Then + lEnd = Len(psString) + vResult = oTextSearch.searchForward(psString, plStart - 1, lEnd) + Else + lEnd = 1 + vResult = oTextSearch.searchForward(psString, plStart, lEnd - 1) + End If With vResult If .subRegExpressions >= 1 Then - plStart = .startOffset(0) + 1 - lEnd = .endOffset(0) + 1 + ' http://www.openoffice.org/api/docs/common/ref/com/sun/star/util/SearchResult.html + Select Case bForward + Case True + plStart = .startOffset(0) + 1 + lEnd = .endOffset(0) + 1 + Case False + plStart = .endOffset(0) + 1 + lEnd = .startOffset(0) + End Select _RegexSearch = Mid(psString, plStart, lEnd - plStart) Else plStart = 0 @@ -953,7 +963,7 @@ Dim lEnd As Long End Function REM ----------------------------------------------------------------------------------------------------------------------- -Function _RegisterEventScript(poObject As Object _ +Public Function _RegisterEventScript(poObject As Object _ , ByVal psEvent As String _ , ByVal psListener As String _ , ByVal psScriptCode As String _ @@ -1061,12 +1071,12 @@ End Function ' Surround REM ----------------------------------------------------------------------------------------------------------------------- Public Function _Trim(ByVal psString As String) As String -' Remove leading and trailing spaces, remove surrounding square brackets +' Remove leading and trailing spaces, remove surrounding square brackets, replace tabs by spaces Const cstSquareOpen = "[" Const cstSquareClose = "]" Dim sTrim As String - sTrim = Trim(psString) + sTrim = Trim(Replace(psString, vbTab, " ")) _Trim = sTrim If Len(sTrim) <= 2 Then Exit Function diff --git a/wizards/source/access2base/acConstants.xba b/wizards/source/access2base/acConstants.xba index a7dcda83879b..e382996b22fc 100644 --- a/wizards/source/access2base/acConstants.xba +++ b/wizards/source/access2base/acConstants.xba @@ -385,11 +385,26 @@ Global Const msoBarTypeFloater = 12 ' Floating window Global Const msoControlButton = 1 ' Command button Global Const msoControlPopup = 10 ' Popup, submenu -REM New Line +REM New Lines REM ----------------------------------------------------------------- +Public Function vbCr() As String : vbCr = Chr(13) : End Function +Public Function vbLf() As String : vbLf = Chr(10) : End Function Public Function vbNewLine() As String Const cstWindows = 1 - If GetGuiType() = cstWindows Then vbNewLine = Chr(13) & Chr(10) Else vbNewLine = Chr(10) + If GetGuiType() = cstWindows Then vbNewLine = vbCR & vbLF Else vbNewLine = vbLF End Function ' vbNewLine V1.4.0 +Public Function vbTab() As String : vbTab = Chr(9) : End Function + +REM Module types +REM ----------------------------------------------------------------- +Global Const acClassModule = 1 +Global Const acStandardModule = 0 + +REM (Module) procedure types +REM ----------------------------------------------------------------- +Global Const vbext_pk_Get = 1 ' A Property Get procedure +Global Const vbext_pk_Let = 2 ' A Property Let procedure +Global Const vbext_pk_Proc = 0 ' A Sub or Function procedure +Global Const vbext_pk_Set = 3 ' A Property Set procedure </script:module>
\ No newline at end of file diff --git a/wizards/source/access2base/script.xlb b/wizards/source/access2base/script.xlb index 67000bc90bfa..a3e5c7820694 100644 --- a/wizards/source/access2base/script.xlb +++ b/wizards/source/access2base/script.xlb @@ -30,4 +30,5 @@ <library:element library:name="UtilProperty"/> <library:element library:name="CommandBar"/> <library:element library:name="CommandBarControl"/> + <library:element library:name="Module"/> </library:library>
\ No newline at end of file |