Skip to content

Commit 6f986c8

Browse files
committed
fixed bug with std input (still has problems with backspace)
fixed bug with closing out window with Esc added example insertion added possibility to pass arguments to scripts added possibility to have other extensions than .txt for arg and result files
1 parent 3dd3034 commit 6f986c8

File tree

8 files changed

+86
-31
lines changed

8 files changed

+86
-31
lines changed

AboutBox1.Designer.vb

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MenuHandler.vb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ Public Class MenuHandler
2929
"<dropDown id='execDropDown' label='ScriptExecutable:' sizeString='12345678901234' getItemCount='GetItemCountExec' getItemID='GetItemIDExec' getItemLabel='GetItemLabelExec' getSelectedItemIndex='GetSelectedExec' onAction='selectItemExec'/>" +
3030
"<buttonGroup id='butGrp'>" +
3131
"<menu id='configMenu' label='Settings'>" +
32+
"<button id='insExample' label='insert Example' tag='5' screentip='insert an Example Script Range' imageMso='SignatureLineInsert' onAction='insertExample'/>" +
3233
"<button id='user' label='User settings' onAction='showAddinConfig' imageMso='ControlProperties' screentip='Show/edit user settings for Script Addin' />" +
3334
"<button id='central' label='Central settings' onAction='showAddinConfig' imageMso='TablePropertiesDialog' screentip='Show/edit central settings for Script Addin' />" +
3435
"<button id='addin' label='ScriptAddin settings' onAction='showAddinConfig' imageMso='ServerProperties' screentip='Show/edit standard Addin settings for Script Addin' />" +
3536
"</menu>" +
36-
"<toggleButton id='debug' label='debug script' onAction='toggleButton' getImage='getImage' getPressed='getPressed' tag='3' screentip='toggles script output window visibility' supertip='for debugging you can display the script output' />" +
37+
"<toggleButton id='debug' label='script output win' onAction='toggleButton' getImage='getImage' getPressed='getPressed' tag='3' screentip='toggles script output window visibility' supertip='for debugging you can display the script output' />" +
3738
"<button id='showLog' label='Log' tag='4' screentip='shows Scriptaddins Diagnostic Display' getImage='getLogsImage' onAction='clickShowLog'/>" +
3839
"</buttonGroup>" +
3940
"<dialogBoxLauncher><button id='dialog' label='About Scriptaddin' onAction='refreshScriptDefs' tag='5' screentip='Show Aboutbox (and refresh ScriptDefinitions from current Workbook from there)'/></dialogBoxLauncher></group>" +
@@ -220,6 +221,13 @@ Public Class MenuHandler
220221
End If
221222
End Function
222223

224+
''' <summary>insert an Script_Example</summary>
225+
''' <param name="control"></param>
226+
Public Sub insertExample(control As IRibbonControl)
227+
ScriptAddin.insertScriptExample()
228+
End Sub
229+
230+
223231
''' <summary>show the trace log</summary>
224232
''' <param name="control"></param>
225233
Public Sub clickShowLog(control As IRibbonControl)

My Project/AssemblyInfo.vb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices
3030
' You can specify all the values or you can default the Build and Revision Numbers
3131
' by using the '*' as shown below:
3232

33-
<Assembly: AssemblyVersion("1.0.0.3")>
34-
<Assembly: AssemblyFileVersion("1.0.0.3")>
33+
<Assembly: AssemblyVersion("1.0.0.4")>
34+
<Assembly: AssemblyFileVersion("1.0.0.4")>

ScriptAddin.vb

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ Public Module ScriptAddin
238238
ScriptExec = defval
239239
ScriptExecArgs = deffilepath
240240
End If
241-
ElseIf deftype = "skipscript" Then
241+
ElseIf deftype = "skipscript" Or deftype = "script" Then
242242
If defval <> "" Then
243-
ReDim Preserve ScriptDefDic("skipscripts")(ScriptDefDic("skipscripts").Length)
244-
ScriptDefDic("skipscripts")(ScriptDefDic("skipscripts").Length - 1) = True
245243
ReDim Preserve ScriptDefDic("scripts")(ScriptDefDic("scripts").Length)
246244
ScriptDefDic("scripts")(ScriptDefDic("scripts").Length - 1) = defval
247245
ReDim Preserve ScriptDefDic("scriptspaths")(ScriptDefDic("scriptspaths").Length)
248246
ScriptDefDic("scriptspaths")(ScriptDefDic("scriptspaths").Length - 1) = deffilepath
247+
ReDim Preserve ScriptDefDic("skipscripts")(ScriptDefDic("skipscripts").Length)
248+
ScriptDefDic("skipscripts")(ScriptDefDic("skipscripts").Length - 1) = (deftype = "skipscript")
249249
End If
250250
ElseIf deftype = "path" And defval <> "" Then
251251
If defval <> "" Then
@@ -284,13 +284,6 @@ Public Module ScriptAddin
284284
ScriptDefDic("diags")(ScriptDefDic("diags").Length - 1) = defval
285285
ReDim Preserve ScriptDefDic("diagspaths")(ScriptDefDic("diagspaths").Length)
286286
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
294287
ElseIf deftype = "dir" Then
295288
dirglobal = defval
296289
ElseIf deftype <> "" Then
@@ -332,7 +325,8 @@ Public Module ScriptAddin
332325
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
333326
Dim value As String = ScriptDefDic(name)(index)
334327
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 = ""
336330
' only for args, results and diags (scripts dont have a target range)
337331
Dim ScriptDataRangeAddress As String = ""
338332
If name = "args" Or name = "results" Or name = "diags" Or name = "scriptrng" Then
@@ -482,6 +476,7 @@ Public Module ScriptAddin
482476

483477
Public fullScriptPath As String
484478
Public script As String
479+
Public scriptarguments As String
485480
Public previousDir As String
486481
Public theScriptOutput As ScriptOutput
487482

@@ -505,6 +500,13 @@ Public Module ScriptAddin
505500
ErrMsg = ""
506501
End If
507502

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+
508510
' absolute paths begin with \\ or X:\ -> dont prefix with currWB path, else currWBpath\scriptpath
509511
Dim curWbPrefix As String = IIf(Left(scriptpath, 2) = "\\" Or Mid(scriptpath, 2, 2) = ":\", "", currWb.Path + "\")
510512
fullScriptPath = curWbPrefix + scriptpath
@@ -679,6 +681,10 @@ Public Module ScriptAddin
679681
' absolute paths begin with \\ or X:\ -> dont prefix with currWB path, else currWBpath\scriptpath
680682
Dim curWbPrefix As String = IIf(Left(readdir, 2) = "\\" Or Mid(readdir, 2, 2) = ":\", "", currWb.Path + "\")
681683
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, " "))
682688
If Not File.Exists(fullScriptPath + "\" + script) Then
683689
ScriptAddin.UserMsg("Script '" + fullScriptPath + "\" + script + "' not found!" + vbCrLf, True, True)
684690
Return False
@@ -889,7 +895,7 @@ Public Module ScriptAddin
889895
''' <param name="questionTitle">optionally pass a title for the msgbox instead of default DBAddin Question</param>
890896
''' <param name="msgboxIcon">optionally pass a different Msgbox icon (style) instead of default MsgBoxStyle.Question</param>
891897
''' <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
893899
Dim theMethod As Object = (New System.Diagnostics.StackTrace).GetFrame(1).GetMethod
894900
Dim caller As String = theMethod.ReflectedType.FullName + "." + theMethod.Name
895901
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
969975
End If
970976
End Sub
971977

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+
9721010
End Module

ScriptOutput.vb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Public Class ScriptOutput
1515

1616
' Add any initialization after the InitializeComponent() call.
1717
Try
18-
Dim args As String = ScriptAddin.ScriptExecArgs + " """ + ScriptAddin.fullScriptPath + "\" + ScriptAddin.script + """"
18+
Dim args As String = ScriptAddin.ScriptExecArgs + " """ + ScriptAddin.fullScriptPath + "\" + ScriptAddin.script + """ " + ScriptAddin.scriptarguments
1919
Directory.SetCurrentDirectory(ScriptAddin.fullScriptPath)
2020
Dim pstartInfo = New ProcessStartInfo With {
2121
.FileName = ScriptAddin.ScriptExec,
@@ -91,16 +91,18 @@ Public Class ScriptOutput
9191
Private Sub ScriptOutput_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
9292
If Not IsNothing(cmd) Then
9393
If e.KeyCode = Keys.Escape Then
94+
cmd.Close()
9495
Me.Hide()
9596
ElseIf e.KeyCode = Keys.Enter Then
96-
cmd.StandardInput.Write(e.KeyCode)
9797
cmd.StandardInput.WriteLine()
98-
Else
99-
cmd.StandardInput.Write(e.KeyCode)
10098
End If
10199
End If
102100
End Sub
103101

102+
Private Sub ScriptOutput_KeyPress(sender As Object, e As KeyPressEventArgs) Handles Me.KeyPress
103+
cmd.StandardInput.Write(e.KeyChar)
104+
End Sub
105+
104106
Private Sub ScriptOutput_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
105107
If Not IsNothing(cmd) Then
106108
Dim procFinished As Boolean = False

0 commit comments

Comments
 (0)