如何从C#应用程序文本中执行的VBScript命令? [英] How to execute VBScript command within textbox from C# application?
本文介绍了如何从C#应用程序文本中执行的VBScript命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么会从放置在C#应用程序TextBox控件执行的VBScript代码?
喜欢,让我们假设我有一个C#Windows应用程序(形式)
并有两个控制!
- 文本框(txtCode)
- 按钮(btnExecute)
txtCode有VBScript代码
我想在btnExecute点击执行VBScript代码!!
时< DIV CLASS =h2_lin>解决方案
您可以直接通过VBS / JS的脚本运行和放大器;通过代码&安培; 。物体周围
一个引用添加到Microsoft脚本控制(COM),那么你就可以;
MSScriptControl.ScriptControl SC =新MSScriptControl.ScriptControl();
[对象] anyParams = {鲍勃};
字符串EXPR = @函数foo(ARG)
昏暗的X:X =你好与& ARG
MSGBOX点¯x
富= 12345
端功能
sc.Language =VBSCRIPT;
sc.AddCode(表达式);
对象result = sc.Run(富,裁判anyParams);
//也
sc.Reset();
结果= sc.Eval(1 + 2/3 + ABS(-99));
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 controls!
- textbox (txtCode)
- button (btnExecute)
txtCode has VBScript code and I want when clicking at btnExecute to execute the VBScript code!!
解决方案
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)");
这篇关于如何从C#应用程序文本中执行的VBScript命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文