@@ -238,14 +238,14 @@ Public Module ScriptAddin
238
238
ScriptExec = defval
239
239
ScriptExecArgs = deffilepath
240
240
End If
241
- ElseIf deftype = "skipscript" Then
241
+ ElseIf deftype = "skipscript" Or deftype = "script" Then
242
242
If defval <> "" Then
243
- ReDim Preserve ScriptDefDic( "skipscripts" )(ScriptDefDic( "skipscripts" ).Length)
244
- ScriptDefDic( "skipscripts" )(ScriptDefDic( "skipscripts" ).Length - 1 ) = True
245
243
ReDim Preserve ScriptDefDic( "scripts" )(ScriptDefDic( "scripts" ).Length)
246
244
ScriptDefDic( "scripts" )(ScriptDefDic( "scripts" ).Length - 1 ) = defval
247
245
ReDim Preserve ScriptDefDic( "scriptspaths" )(ScriptDefDic( "scriptspaths" ).Length)
248
246
ScriptDefDic( "scriptspaths" )(ScriptDefDic( "scriptspaths" ).Length - 1 ) = deffilepath
247
+ ReDim Preserve ScriptDefDic( "skipscripts" )(ScriptDefDic( "skipscripts" ).Length)
248
+ ScriptDefDic( "skipscripts" )(ScriptDefDic( "skipscripts" ).Length - 1 ) = (deftype = "skipscript" )
249
249
End If
250
250
ElseIf deftype = "path" And defval <> "" Then
251
251
If defval <> "" Then
@@ -284,13 +284,6 @@ Public Module ScriptAddin
284
284
ScriptDefDic( "diags" )(ScriptDefDic( "diags" ).Length - 1 ) = defval
285
285
ReDim Preserve ScriptDefDic( "diagspaths" )(ScriptDefDic( "diagspaths" ).Length)
286
286
ScriptDefDic( "diagspaths" )(ScriptDefDic( "diagspaths" ).Length - 1 ) = deffilepath
287
- ElseIf deftype = "script" Then
288
- ReDim Preserve ScriptDefDic( "scripts" )(ScriptDefDic( "scripts" ).Length)
289
- ScriptDefDic( "scripts" )(ScriptDefDic( "scripts" ).Length - 1 ) = defval
290
- ReDim Preserve ScriptDefDic( "scriptspaths" )(ScriptDefDic( "scriptspaths" ).Length)
291
- ScriptDefDic( "scriptspaths" )(ScriptDefDic( "scriptspaths" ).Length - 1 ) = deffilepath
292
- ReDim Preserve ScriptDefDic( "skipscripts" )(ScriptDefDic( "skipscripts" ).Length)
293
- ScriptDefDic( "skipscripts" )(ScriptDefDic( "skipscripts" ).Length - 1 ) = False
294
287
ElseIf deftype = "dir" Then
295
288
dirglobal = defval
296
289
ElseIf deftype <> "" Then
@@ -332,7 +325,8 @@ Public Module ScriptAddin
332
325
Private Function prepareParam(index As Integer , name As String , ByRef ScriptDataRange As Range, ByRef returnName As String , ByRef returnPath As String , ext As String ) As String
333
326
Dim value As String = ScriptDefDic(name)(index)
334
327
If value = "" Then Return "Empty definition value for parameter " + name + ", index: " + index.ToString()
335
-
328
+ ' allow for other extensions than txt if defined in ScriptDefDic(name)(index)
329
+ If InStr(value, "." ) > 0 Then ext = ""
336
330
' only for args, results and diags (scripts dont have a target range)
337
331
Dim ScriptDataRangeAddress As String = ""
338
332
If name = "args" Or name = "results" Or name = "diags" Or name = "scriptrng" Then
@@ -482,6 +476,7 @@ Public Module ScriptAddin
482
476
483
477
Public fullScriptPath As String
484
478
Public script As String
479
+ Public scriptarguments As String
485
480
Public previousDir As String
486
481
Public theScriptOutput As ScriptOutput
487
482
@@ -505,6 +500,13 @@ Public Module ScriptAddin
505
500
ErrMsg = ""
506
501
End If
507
502
503
+ ' a blank separator indicates additional arguments, separate argument passing because of possible blanks in path -> need quotes around path + scriptname
504
+ ' assumption: scriptname itself may not have blanks in it.
505
+ If InStr(script, " " ) > 0 Then
506
+ scriptarguments = script.Substring(InStr(script, " " ))
507
+ script = script.Substring( 0 , InStr(script, " " ) - 1 )
508
+ End If
509
+
508
510
' absolute paths begin with \\ or X:\ -> dont prefix with currWB path, else currWBpath\scriptpath
509
511
Dim curWbPrefix As String = IIf(Left(scriptpath, 2 ) = "\\" Or Mid(scriptpath, 2 , 2 ) = ":\" , "" , currWb.Path + "\" )
510
512
fullScriptPath = curWbPrefix + scriptpath
@@ -679,6 +681,10 @@ Public Module ScriptAddin
679
681
' absolute paths begin with \\ or X:\ -> dont prefix with currWB path, else currWBpath\scriptpath
680
682
Dim curWbPrefix As String = IIf(Left(readdir, 2 ) = "\\" Or Mid(readdir, 2 , 2 ) = ":\" , "" , currWb.Path + "\" )
681
683
Dim fullScriptPath = curWbPrefix + readdir
684
+
685
+ ' a blank separator indicates additional arguments, separate argument passing because of possible blanks in path -> need quotes around path + scriptname
686
+ ' assumption: scriptname itself may not have blanks in it.
687
+ If InStr(script, " " ) > 0 Then script = script.Substring( 0 , InStr(script, " " ))
682
688
If Not File.Exists(fullScriptPath + "\" + script) Then
683
689
ScriptAddin.UserMsg( "Script '" + fullScriptPath + "\" + script + "' not found!" + vbCrLf, True , True )
684
690
Return False
@@ -889,7 +895,7 @@ Public Module ScriptAddin
889
895
''' <param name="questionTitle">optionally pass a title for the msgbox instead of default DBAddin Question</param>
890
896
''' <param name="msgboxIcon">optionally pass a different Msgbox icon (style) instead of default MsgBoxStyle.Question</param>
891
897
''' <returns>choice as MsgBoxResult (Yes, No, OK, Cancel...)</returns>
892
- Public Function QuestionMsg(theMessage As String , Optional questionType As MsgBoxStyle = MsgBoxStyle.OkCancel, Optional questionTitle As String = "DBAddin Question" , Optional msgboxIcon As MsgBoxStyle = MsgBoxStyle.Question) As MsgBoxResult
898
+ Public Function QuestionMsg(theMessage As String , Optional questionType As MsgBoxStyle = MsgBoxStyle.OkCancel, Optional questionTitle As String = "ScriptAddin Question" , Optional msgboxIcon As MsgBoxStyle = MsgBoxStyle.Question) As MsgBoxResult
893
899
Dim theMethod As Object = ( New System.Diagnostics.StackTrace).GetFrame( 1 ).GetMethod
894
900
Dim caller As String = theMethod.ReflectedType.FullName + "." + theMethod.Name
895
901
WriteToLog(theMessage, If (msgboxIcon = MsgBoxStyle.Critical Or msgboxIcon = MsgBoxStyle.Exclamation, EventLogEntryType.Warning, EventLogEntryType.Information), caller) ' to avoid popup of trace log
@@ -969,4 +975,36 @@ Public Module ScriptAddin
969
975
End If
970
976
End Sub
971
977
978
+ Public Sub insertScriptExample()
979
+ If QuestionMsg( "Inserting Example Script definition starting in current cell, overwriting 8 rows and 3 columns with example definitions!" ) = MsgBoxResult.Cancel Then Exit Sub
980
+ Dim curCell As Range = ExcelDnaUtil.Application.ActiveCell
981
+ curCell.Value = "Dir"
982
+ curCell.Offset( 0 , 1 ).Value = "."
983
+ curCell.Offset( 1 , 0 ).Value = "Type"
984
+ curCell.Offset( 1 , 1 ).Value = "R"
985
+ curCell.Offset( 2 , 0 ).Value = "script"
986
+ curCell.Offset( 2 , 1 ).Value = "yourScript.R"
987
+ curCell.Offset( 2 , 2 ).Value = "."
988
+ curCell.Offset( 3 , 0 ).Value = "scriptCell"
989
+ curCell.Offset( 3 , 1 ).Value = "# your script code in this cell"
990
+ curCell.Offset( 3 , 2 ).Value = "."
991
+ curCell.Offset( 4 , 0 ).Value = "scriptRange"
992
+ curCell.Offset( 4 , 1 ).Value = "yourScriptCodeInThisRange"
993
+ curCell.Offset( 4 , 2 ).Value = "."
994
+ curCell.Offset( 5 , 0 ).Value = "arg"
995
+ curCell.Offset( 5 , 1 ).Value = "yourArgInputRange"
996
+ curCell.Offset( 5 , 2 ).Value = "."
997
+ curCell.Offset( 6 , 0 ).Value = "res"
998
+ curCell.Offset( 6 , 1 ).Value = "yourResultOutRange"
999
+ curCell.Offset( 6 , 2 ).Value = "."
1000
+ curCell.Offset( 7 , 0 ).Value = "diag"
1001
+ curCell.Offset( 7 , 1 ).Value = "yourDiagramPlaceRange"
1002
+ curCell.Offset( 7 , 2 ).Value = "."
1003
+ Try
1004
+ ExcelDnaUtil.Application.ActiveSheet.Range(curCell, curCell.Offset( 7 , 2 )).Name = "Script_Example"
1005
+ Catch ex As Exception
1006
+ UserMsg( "Couldn't name example definitions as 'Script_Example': " + ex.Message)
1007
+ End Try
1008
+ End Sub
1009
+
972
1010
End Module
0 commit comments