Skip to content

Commit 571ebe7

Browse files
committed
add setExecutionParam and getExecutionParam for VBA parameter handling
simplified WriteToLog code
1 parent 8784ace commit 571ebe7

File tree

8 files changed

+75
-16
lines changed

8 files changed

+75
-16
lines changed

Distribution/DBaddin32.xll

0 Bytes
Binary file not shown.

Distribution/DBaddin64.xll

0 Bytes
Binary file not shown.

docs/DBModif.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,30 @@ The DBModifiers can be executed either
102102

103103
... or be done on saving the Workbook.
104104

105-
... or by issuing the VBA command `result = Application.Run("executeDBModif", <DBModifierName>, <headlessFlag>)`, where `<DBModifierName>` is the Name of the DB Modifier including the type (so `DBMapperemployee` or `DBActionpublishersDelete`) and `<headlessFlag>` is a boolean flag indicating whether any user-interaction (as controllable by the Addin) should be avoided, all errors are returned in the `result` of the call.
105+
... or by issuing the VBA command `result = Application.Run("executeDBModif", <DBModifierName>, <headlessFlag>)`, where `<DBModifierName>` is the name of the DB Modifier including the type (so `DBMapperemployee` or `DBActionpublishersDelete`) and `<headlessFlag>` is a boolean flag indicating whether any user-interaction (as controllable by the Addin) should be avoided, all errors collected in `nonInteractiveErrMsgs` and returned in the `result` of the call.
106106

107107
You can edit the DBModifiers either by Ctrl-Shift clicking the Execute DBModifier Groups dropdown menus..
108108
.. or by Ctrl-Shift clicking the created command-buttons.
109109
.. or by using the Insert/Edit DBFunc/DBModif context menu within a DBMapper or DBAction range.
110110

111+
## Additional macro functions available for setting/accessing settings
112+
113+
By issuing the VBA command `Application.Run("setExecutionParam", Param, Value)`, where `Param` is the name of the parameter and `Value` is the value it should be set to, following settings can be set via VBA:
114+
* headLess: sets nonInteractive to True or False
115+
* selectedEnvironment: sets SettingsTools.selectedEnvironment to the value passed (zero based environment: 0 is the first, 1 the second, etc.)
116+
* ConstConnString: sets SettingsTools.ConstConnString to the value passed
117+
* CnnTimeout: sets SettingsTools.CnnTimeout to the value passed
118+
* CmdTimeout: sets SettingsTools.CmdTimeout to the value passed
119+
120+
By issuing the VBA command `result = Application.Run("getExecutionParam", Param)`, where `Param` is the name of the parameter the current settings of the following parameters are returned:
121+
* selectedEnvironment: returns SettingsTools.selectedEnvironment (zero based environment: 0 is the first, 1 the second, etc.)
122+
* env() : returns the selected environment (1 is the first, 2 the second, etc.)
123+
* ConstConnString: returns SettingsTools.ConstConnString
124+
* CnnTimeout: returns SettingsTools.CnnTimeout
125+
* CmdTimeout: returns SettingsTools.CmdTimeout
126+
* nonInteractiveErrMsgs: returns the currently collected error messages
127+
* and any other key from the available DBAddin settings (in DBAddin.xll.config, DBAddinCentral.config or DBaddinUser.config)
128+
111129
## Additional settings ("hidden" as they are not available in creation dialogs)
112130

113131
Following Settings of DBModifiers can only be edited in the Edit DBModifier Definitions Window:

source/DBModif.vb

+50-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ Public Class DBMapper : Inherits DBModif
437437
preventColResize = Convert.ToBoolean(getParamFromXML(definitionXML, "preventColResize", "Boolean"))
438438
deleteBeforeMapperInsert = Convert.ToBoolean(getParamFromXML(definitionXML, "deleteBeforeMapperInsert", "Boolean"))
439439
onlyRefreshTheseDBSheetLookups = getParamFromXML(definitionXML, "onlyRefreshTheseDBSheetLookups")
440-
' set table styles for DBMappers having a listobject underneath
440+
' set table styles for DBMappers having a list-object underneath
441441
Dim DBmapperListObj As Excel.ListObject = Nothing
442442
Try : DBmapperListObj = TargetRange.ListObject : Catch ex As Exception : End Try
443443
If DBmapperListObj IsNot Nothing Then
@@ -2243,6 +2243,55 @@ EndOuterLoop:
22432243
End If
22442244
End Function
22452245

2246+
''' <summary>set given execution parameter, used for VBA call by Application.Run</summary>
2247+
''' <param name="Param">execution parameter, like "selectedEnvironment" (zero based here!) or "CnnTimeout"</param>
2248+
''' <param name="Value">execution parameter value</param>
2249+
<ExcelCommand(Name:="setExecutionParam")>
2250+
Public Sub setExecutionParam(Param As String, Value As Object)
2251+
Try
2252+
If Param = "headLess" Then
2253+
nonInteractive = Value
2254+
nonInteractiveErrMsgs = "" ' reset non-interactive messages
2255+
ElseIf Param = "selectedEnvironment" Then
2256+
SettingsTools.selectedEnvironment = Value
2257+
theRibbon.Invalidate()
2258+
ElseIf Param = "ConstConnString" Then
2259+
SettingsTools.ConstConnString = Value
2260+
ElseIf Param = "CnnTimeout" Then
2261+
SettingsTools.CnnTimeout = Value
2262+
ElseIf Param = "CmdTimeout" Then
2263+
SettingsTools.CmdTimeout = Value
2264+
Else
2265+
UserMsg("parameter " + Param + " not supported by setExecutionParams")
2266+
Exit Sub
2267+
End If
2268+
Catch ex As Exception
2269+
UserMsg("setting parameter " + Param + " with value " + CStr(Value) + " resulted in error " + ex.Message)
2270+
End Try
2271+
End Sub
2272+
2273+
''' <summary>get given execution parameter or setting parameter found by fetchSetting, used for VBA call by Application.Run</summary>
2274+
''' <param name="Param">execution parameter, like "selectedEnvironment" (zero based here!), "env()" or "CnnTimeout"</param>
2275+
''' <returns>execution or setting parameter value</returns>
2276+
<ExcelCommand(Name:="getExecutionParam")>
2277+
Public Function getExecutionParam(Param As String) As Object
2278+
If Param = "selectedEnvironment" Then
2279+
Return SettingsTools.selectedEnvironment
2280+
ElseIf Param = "env()" Then
2281+
Return SettingsTools.env()
2282+
ElseIf Param = "ConstConnString" Then
2283+
Return SettingsTools.ConstConnString
2284+
ElseIf Param = "CnnTimeout" Then
2285+
Return SettingsTools.CnnTimeout
2286+
ElseIf Param = "CmdTimeout" Then
2287+
Return SettingsTools.CmdTimeout
2288+
ElseIf Param = "nonInteractiveErrMsgs" Then
2289+
Return nonInteractiveErrMsgs
2290+
Else
2291+
Return fetchSetting(Param, "parameter " + Param + " neither supported by getExecutionParam nor found with fetchSetting(Param)")
2292+
End If
2293+
End Function
2294+
22462295
''' <summary>marks a row in a DBMapper for deletion, used as a ExcelCommand to have a keyboard shortcut</summary>
22472296
<ExcelCommand(Name:="deleteRow")>
22482297
Public Sub deleteRow()

source/Logging.vb

+3-11
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,13 @@ Public Module Logging
2929
theLogDisplaySource.TraceEvent(TraceEventType.Information, timestamp, "Non-interactive: {0}: {1}", caller, Message)
3030
theLogFileSource.TraceEvent(TraceEventType.Information, timestamp, "Non-interactive: {0}: {1}", caller, Message)
3131
Else
32+
theLogDisplaySource.TraceEvent(eEventType, timestamp, "{0}: {1}", caller, Message)
33+
theLogFileSource.TraceEvent(eEventType, timestamp, "{0}: {1}", caller, Message)
3234
Select Case eEventType
33-
Case TraceEventType.Information
34-
theLogDisplaySource.TraceEvent(TraceEventType.Information, timestamp, "{0}: {1}", caller, Message)
35-
theLogFileSource.TraceEvent(TraceEventType.Information, timestamp, "{0}: {1}", caller, Message)
36-
Case TraceEventType.Warning
37-
theLogDisplaySource.TraceEvent(TraceEventType.Warning, timestamp, "{0}: {1}", caller, Message)
38-
theLogFileSource.TraceEvent(TraceEventType.Warning, timestamp, "{0}: {1}", caller, Message)
35+
Case TraceEventType.Warning, TraceEventType.Error
3936
WarningIssued = True
4037
' at Addin Start ribbon has not been loaded so avoid call to it here..
4138
If theRibbon IsNot Nothing Then theRibbon.InvalidateControl("showLog")
42-
Case TraceEventType.Error
43-
theLogDisplaySource.TraceEvent(TraceEventType.Error, timestamp, "{0}: {1}", caller, Message)
44-
theLogFileSource.TraceEvent(TraceEventType.Error, timestamp, "{0}: {1}", caller, Message)
45-
WarningIssued = True
46-
If theRibbon IsNot Nothing Then theRibbon.InvalidateControl("showLog")
4739
End Select
4840
End If
4941
Catch ex As Exception

source/My Project/AssemblyInfo.vb

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ Imports System.Runtime.InteropServices
3131
' You can specify all the values or you can default the Build and Revision Numbers
3232
' by using the '*' as shown below:
3333

34-
<Assembly: AssemblyVersion("1.0.0.70")>
35-
<Assembly: AssemblyFileVersion("1.0.0.70")>
34+
<Assembly: AssemblyVersion("1.0.0.71")>
35+
<Assembly: AssemblyFileVersion("1.0.0.71")>
3636
<Assembly: NeutralResourcesLanguage("de-DE")>

source/SettingsTools.vb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Public Module SettingsTools
1717
Public CmdTimeout As Integer
1818
''' <summary>default formatting style used in DBDate</summary>
1919
Public DefaultDBDateFormatting As Integer
20-
''' <summary>The path where the User specific settings (overrides) can be found</summary>
20+
''' <summary>The path where the User specific settings (overrides of standard/global settings) can be found (hardcoded to path of xll)</summary>
2121
Private UserSettingsPath As String
2222

2323
''' <summary>exception proof fetching of integer settings</summary>

test/DBMapperTests.xlsm

5.23 KB
Binary file not shown.

0 commit comments

Comments
 (0)