Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using MSScriptControl;
  11.  
  12. namespace Blog.Script
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void Form1_Load(object sender, EventArgs e)
  22.         {
  23.             ScriptControlClass script = new ScriptControlClass();
  24.             script.Language = "JScript";
  25.             script.AddCode("var v = 10;");
  26.  
  27.             StringBuilder js = new StringBuilder();
  28.             js.AppendLine("function max(x,y){ return x > y ? x : y; }");
  29.             js.AppendLine("max(v,3);");
  30.  
  31.             string result = "";
  32.  
  33.             try
  34.             {
  35.                 result = script.Eval(js.ToString()).ToString();
  36.             }
  37.             catch
  38.             {
  39.                 result = script.Error.Line + "," + script.Error.Column + " " + script.Error.Description;
  40.             }
  41.             MessageBox.Show(result);
  42.  
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement