foxtable很多用法都自己处理了错误,没有抛出异常,这确实是一个弊端,但是暂时没有办法,动态函数,需要先保证代码是可以编译通过的。
至于代码中的逻辑错误可以在动态代码里使用try
Dim Code As String
Code = "try" & vbcrlf
Code = Code & "Dim Val1 As Integer = 1" & vbcrlf
Code = Code & "Dim Val2 As Integer = 0" & vbcrlf
Code = Code & "Dim Sum As Integer = Val1 / Val2" & vbcrlf
Code = Code & "Return Sum" & vbcrlf
Code = Code & "Catch ex As Exception" & vbcrlf
Code = Code & "msgbox(ex.message)" & vbcrlf
Code = Code & "return -1" & vbcrlf
Code = Code & "end try"
Output.Show(code)
Functions.remove("Sum")
Functions.Add("Sum",Code)
Functions.Complie()
Dim a = Functions.Execute("Sum")
If a = -1 Then
msgbox("出错")
End If