How to execute VBScript command within textbox from C# application?

后端 未结 4 1293
面向向阳花
面向向阳花 2021-01-15 03:20

How could I execute VBScript\'s code from TextBox control placed in C# application?

like , let\'s assume that I have a C# Windows Application(form) and has two contr

相关标签:
4条回答
  • 2021-01-15 03:45

    You will need to use WebBrowser Control to do that.

    And since i don't think you can inject VBScript code in the loaded page. So what you can do is Create a Temp .html page, save your TextBox's script in it and then Load it in the the WebBrowser Control.

    0 讨论(0)
  • 2021-01-15 03:52

    Couldn't you simply write it to a file and execute it using the default Windows behavior or something like that? It's the only way I can think of.

    0 讨论(0)
  • 2021-01-15 03:56

    Check out this two articles:
    http://msdn.microsoft.com/en-gb/magazine/cc301954.aspx
    http://msdn.microsoft.com/en-us/library/ms974577.aspx

    0 讨论(0)
  • 2021-01-15 03:59

    You can pass VBS/JS directly to the scripting runtime & pass code & objects around.

    Add a ref to the Microsoft Scripting Control (COM) then you can;

    MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
    object[] anyParams = { "Bob"};
    string expr = @"function foo(arg)
        dim x: x = ""Hello "" & arg 
        msgbox x
        foo = 12345 
        End function";
    
    sc.Language = "VBScript";
    sc.AddCode(expr);
    
    object result = sc.Run("foo", ref anyParams);
    
    //also
    sc.Reset();
    result = sc.Eval("1 + 2 / 3 + abs(-99)");
    
    0 讨论(0)
提交回复
热议问题