Skip to content

Commit

Permalink
Merge pull request #5611 from Ivanluv/ShowError#5604
Browse files Browse the repository at this point in the history
Show error#5604
  • Loading branch information
maxwellfundi authored Feb 3, 2020
2 parents 2262d16 + e3e6754 commit 07ec9b8
Show file tree
Hide file tree
Showing 23 changed files with 801 additions and 14,028 deletions.
14 changes: 9 additions & 5 deletions instat/clsRLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -597,27 +597,27 @@ Public Class RLink
End If
End Sub

Public Function RunInternalScriptGetValue(strScript As String, Optional strVariableName As String = ".temp_value", Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing) As SymbolicExpression
Public Function RunInternalScriptGetValue(strScript As String, Optional strVariableName As String = ".temp_value", Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing, Optional ByRef strError As String = "") As SymbolicExpression
Dim expTemp As SymbolicExpression
Dim strCommand As String

expTemp = Nothing
'TODO Bug here if strScript is multiple lines. Wrong value will be returned
strCommand = strVariableName & "<-" & strScript
If clsEngine IsNot Nothing Then
Evaluate(strCommand, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
Evaluate(strCommand, bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride, strError:=strError)
expTemp = GetSymbol(strVariableName, bSilent:=True)
'Very important to remove the variable after getting it othewise could be returning wrong variable later if a command gives an error
Evaluate("rm(" & strVariableName & ")", bSilent:=bSilent, bSeparateThread:=bSeparateThread)
End If
Return expTemp
End Function

Public Function RunInternalScriptGetOutput(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing) As CharacterVector
Public Function RunInternalScriptGetOutput(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing, Optional ByRef strError As String = "") As CharacterVector
Dim chrTemp As CharacterVector
Dim expTemp As SymbolicExpression

expTemp = RunInternalScriptGetValue("capture.output(" & strScript & ")", bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride)
expTemp = RunInternalScriptGetValue("capture.output(" & strScript & ")", bSilent:=bSilent, bSeparateThread:=bSeparateThread, bShowWaitDialogOverride:=bShowWaitDialogOverride, strError:=strError)
Try
chrTemp = expTemp.AsCharacter()
Catch ex As Exception
Expand Down Expand Up @@ -646,14 +646,15 @@ Public Class RLink
End If
End Function

Private Function Evaluate(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing) As Boolean
Private Function Evaluate(strScript As String, Optional bSilent As Boolean = False, Optional bSeparateThread As Boolean = True, Optional bShowWaitDialogOverride As Nullable(Of Boolean) = Nothing, Optional ByRef strError As String = "") As Boolean
Dim thrRScript As Threading.Thread
Dim thrDelay As Threading.Thread
Dim thrWaitDisplay As Threading.Thread
Dim evtWaitHandleWaitDisplayDone As New System.Threading.AutoResetEvent(False)
Dim evtWaitHandleDelayDone As New System.Threading.AutoResetEvent(False)
Dim bReturn As Boolean = True
Dim i As Integer = 1
Dim strTempError As String = ""
Dim strTempFile As String
Dim bErrorMessageOpen As Boolean = False
Dim bCurrentShowWaiting As Boolean
Expand Down Expand Up @@ -721,6 +722,7 @@ Public Class RLink
MsgBox(ex.Message & Environment.NewLine & "The error occurred in attempting to run the following R command(s):" & Environment.NewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
bErrorMessageOpen = False
End If
strTempError = ex.Message
bReturn = False
End Try
End Sub)
Expand Down Expand Up @@ -763,12 +765,14 @@ Public Class RLink
If Not bSilent Then
MsgBox(ex.Message & Environment.NewLine & "The error occurred in attempting to run the following R command(s):" & Environment.NewLine & strScript, MsgBoxStyle.Critical, "Error running R command(s)")
End If
strTempError = ex.Message
bReturn = False
End Try
Else
bReturn = False
End If
bRCodeRunning = False
strError = strTempError
Return bReturn
End Function

Expand Down
82 changes: 8 additions & 74 deletions instat/dlgCalculator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Public Class dlgCalculator
ucrCalc.chkSaveResultInto.Checked = True
SaveResults()
ucrCalc.ucrSelectorForCalculations.bUseCurrentFilter = False
ucrCalc.ucrTryModelling.SetRSyntax(ucrBase.clsRsyntax)
ucrBase.Visible = True
End Sub

Expand All @@ -69,17 +70,22 @@ Public Class dlgCalculator
Private Sub InitialiseDialog()
ucrBase.iHelpTopicID = 14
ucrCalc.ucrReceiverForCalculation.SetMeAsReceiver()
ucrCalc.ucrTryModelling.SetIsCommand()
ucrCalc.ucrTryModelling.SetReceiver(ucrCalc.ucrReceiverForCalculation)
clsAttach.SetRCommand("attach")
clsDetach.SetRCommand("detach")
clsAttach.AddParameter("what", clsRFunctionParameter:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame)
clsDetach.AddParameter("name", clsRFunctionParameter:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame)
clsDetach.AddParameter("unload", "TRUE")
ucrBase.clsRsyntax.AddToBeforeCodes(clsAttach)
ucrBase.clsRsyntax.AddToAfterCodes(clsDetach)
ucrBase.clsRsyntax.SetCommandString("")
ucrCalc.ucrSaveResultInto.SetItemsTypeAsColumns()
ucrCalc.ucrSaveResultInto.SetDefaultTypeAsColumn()
ucrCalc.ucrSaveResultInto.SetDataFrameSelector(ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames)
ucrCalc.ucrSelectorForCalculations.Reset()
ucrCalc.ucrSaveResultInto.SetValidationTypeAsRVariable()
ucrCalc.ucrTryModelling.StrvecOutputRequired()
End Sub

Private Sub ucrCalc_SaveNameChanged() Handles ucrCalc.SaveNameChanged
Expand All @@ -98,27 +104,13 @@ Public Class dlgCalculator
ucrBase.clsRsyntax.bExcludeAssignedFunctionOutput = False
End If
End Sub

Private Sub ucrBase_BeforeClickOk(sender As Object, e As EventArgs) Handles ucrBase.BeforeClickOk
Dim strScript As String = ""
Dim strFunc As String
clsAttach.AddParameter("what", clsRFunctionParameter:=ucrCalc.ucrSelectorForCalculations.ucrAvailableDataFrames.clsCurrDataFrame)
strFunc = clsAttach.ToScript(strScript)
frmMain.clsRLink.RunScript(strScript & strFunc)
End Sub

Private Sub ucrBase_ClickOk(sender As Object, e As EventArgs) Handles ucrBase.ClickOk
Dim strScript As String = ""
Dim strFunc As String
strFunc = clsDetach.ToScript(strScript)
frmMain.clsRLink.RunScript(strScript & strFunc)
ucrCalc.SetCalculationHistory()
End Sub

Private Sub ucrCalc_SelectionChanged() Handles ucrCalc.SelectionChanged
ucrBase.clsRsyntax.SetCommandString(ucrCalc.ucrReceiverForCalculation.GetVariableNames(False))
ucrCalc.ucrInputTryMessage.SetName("")
ucrCalc.cmdTry.Enabled = Not ucrCalc.ucrReceiverForCalculation.IsEmpty()
ucrCalc.ucrTryModelling.ucrInputTryMessage.SetName("")
TestOKEnabled()
End Sub

Expand Down Expand Up @@ -168,7 +160,7 @@ Public Class dlgCalculator
End Sub

Private Sub ucrSelectorForCalculations_DataframeChanged() Handles ucrCalc.DataFrameChanged
ucrCalc.ucrInputTryMessage.SetName("")
ucrCalc.ucrTryModelling.ucrInputTryMessage.SetName("")
SaveResults()
End Sub

Expand All @@ -179,62 +171,4 @@ Public Class dlgCalculator
ucrCalc.ucrSaveResultInto.Visible = False
End If
End Sub

Private Sub TryScript()
Dim strOutPut As String
Dim strAttach As String
Dim strDetach As String
Dim strTempScript As String = ""
Dim strVecOutput As CharacterVector
Dim bIsAssigned As Boolean
Dim bToBeAssigned As Boolean
Dim strAssignTo As String
Dim strAssignToColumn As String
Dim strAssignToDataFrame As String

bIsAssigned = ucrBase.clsRsyntax.GetbIsAssigned()
bToBeAssigned = ucrBase.clsRsyntax.GetbToBeAssigned()
strAssignTo = ucrBase.clsRsyntax.GetstrAssignTo()
'These should really be done through RSyntax methods as above
strAssignToColumn = ucrBase.clsRsyntax.GetstrAssignToColumn()
strAssignToDataFrame = ucrBase.clsRsyntax.GetstrAssignToDataFrame()

Try
If ucrCalc.ucrReceiverForCalculation.IsEmpty Then
ucrCalc.ucrInputTryMessage.SetName("")
Else
'get strScript here
strAttach = clsAttach.ToScript(strTempScript)
frmMain.clsRLink.RunInternalScript(strTempScript & strAttach, bSilent:=True)
ucrBase.clsRsyntax.RemoveAssignTo()
strOutPut = ucrBase.clsRsyntax.GetScript
strVecOutput = frmMain.clsRLink.RunInternalScriptGetOutput(strOutPut, bSilent:=True)
If strVecOutput IsNot Nothing Then
If strVecOutput.Length > 1 Then
ucrCalc.ucrInputTryMessage.SetName(Mid(strVecOutput(0), 5) & "...")
Else
ucrCalc.ucrInputTryMessage.SetName(Mid(strVecOutput(0), 5))
End If
Else
ucrCalc.ucrInputTryMessage.SetName("Command produced an error or no output to display.")
End If
End If
Catch ex As Exception
ucrCalc.ucrInputTryMessage.SetName("Command produced an error. Modify input before running.")
Finally
strTempScript = ""
strDetach = clsDetach.ToScript(strTempScript)
frmMain.clsRLink.RunInternalScript(strTempScript & strDetach, bSilent:=True)
ucrBase.clsRsyntax.SetbIsAssigned(bIsAssigned)
ucrBase.clsRsyntax.SetbToBeAssigned(bToBeAssigned)
ucrBase.clsRsyntax.SetstrAssignTo(strAssignTo)
'These should really be done through RSyntax methods as above
ucrBase.clsRsyntax.SetstrAssignToColumn(strAssignToColumn)
ucrBase.clsRsyntax.SetstrAssignToDataFrame(strAssignToDataFrame)
End Try
End Sub

Private Sub cmdTry_Click() Handles ucrCalc.TryCommadClick
TryScript()
End Sub
End Class
28 changes: 8 additions & 20 deletions instat/dlgEnter.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07ec9b8

Please sign in to comment.