public object CompileAndRunCode(string VBCodeToExecute) { string sReturn_DataType = null; string sReturn_Value = ""; try { // Instance our CodeDom wrapper cVBEvalProvider ep = new cVBEvalProvider(); /// Big Time StringBuilder sbr = new StringBuilder(); sbr.Append("Dim Field As String = String.Empty" + "\r\n"); sbr.Append(VBCodeToExecute + "\r\n"); sbr.Append("Return Field"); // Compile and run object objResult = ep.Eval(sbr.ToString()); if (ep.CompilerErrors.Count != 0) { //System.Diagnostics.Debug.WriteLine("CompileAndRunCode: Compile Error Count = " + ep.CompilerErrors.Count); //System.Diagnostics.Debug.WriteLine(ep.CompilerErrors[0]); ScriptManager.RegisterStartupScript(this, this.GetType(), "error", "alert('Error: " + ep.CompilerErrors[0] + "');", true); return("ERROR"); } Type t = objResult.GetType(); if (t.ToString() == "System.String") { sReturn_DataType = t.ToString(); sReturn_Value = Convert.ToString(objResult); } else { // Some other type of data - not really handled at // this point. rwd } } catch (Exception ex) { rtxtOutput.Text = sReturn_Value; rtxtOutput.Text = "Error: " + ex.Message; } return(sReturn_Value); }
public object CompileAndRunCode(string VBCodeToExecute) { string sReturn_DataType = null; string sReturn_Value = ""; try { // Instance our CodeDom wrapper cVBEvalProvider ep = new cVBEvalProvider(); /// Big Time StringBuilder sbr = new StringBuilder(); sbr.Append("Dim Field As String = String.Empty" + "\r\n"); sbr.Append(VBCodeToExecute + "\r\n"); sbr.Append("Return Field"); // Compile and run object objResult = ep.Eval(sbr.ToString()); if (ep.CompilerErrors.Count != 0) { //System.Diagnostics.Debug.WriteLine("CompileAndRunCode: Compile Error Count = " + ep.CompilerErrors.Count); //System.Diagnostics.Debug.WriteLine(ep.CompilerErrors[0]); ScriptManager.RegisterStartupScript(this, this.GetType(), "error", "alert('Error: " + ep.CompilerErrors[0] + "');", true); return "ERROR"; } Type t = objResult.GetType(); if (t.ToString() == "System.String") { sReturn_DataType = t.ToString(); sReturn_Value = Convert.ToString(objResult); } else { // Some other type of data - not really handled at // this point. rwd } } catch (Exception ex) { rtxtOutput.Text = sReturn_Value; rtxtOutput.Text = "Error: " + ex.Message; } return sReturn_Value; }