如何通过.NET执行Minitab命令?
问题描述:
Minitab帮助文件在一定程度上为此主题提供支持,所有示例都在VB中。我是.NET新手,但我很快就采用它。它在命令的语法中。如何通过.NET执行Minitab命令?
他们在VB中提供这个例子:
Dim MtbApp As New mtb.Application
Dim MtbProj As mtb.Project
Dim MtbCom As mtb.Command
Dim i, j As Integer
MtbApp.UserInterface.Visible = True
Set MtbProj = MtbApp.ActiveProject
MtbProj.ExecuteCommand "RANDOM 30 C1 - C2"
MtbProj.ExecuteCommand "REGRESS C1 1 C2"
和我的代码看起来像这样在C#
var MtbApp = new Mtb.Application();
var MtbProj = new Mtb.Project();
MtbProj = MtbApp.ActiveProject;
MtbApp.UserInterface.Visible = true;
MtbProj.ExecuteCommand(<command>);
什么,我期待应该发生在Minitab中应打开,命令应该执行。然而,最近发生的事情是Minitab的两个实例正在打开,而且都没有显示用户界面,我必须在进程中找到它们。
答
假设你已经添加了参考Minitab的COM,这应该让你开始:
Mtb.Application MtbApp = null;
Mtb.Project MtbProj = null;
Mtb.UserInterface MtbUI = null;
MtbApp = new Mtb.Application();
MtbProj = MtbApp.ActiveProject;
MtbUI = MtbApp.UserInterface;
MtbUI.Visible = true;
MtbProj.ExecuteCommand("RANDOM 30 C1-C2", Type.Missing); //with C# optional params required
MtbApp.Quit();
Marshal.ReleaseComObject(MtbUI); MtbUI = null;
Marshal.ReleaseComObject(MtbProj); MtbProj = null;
Marshal.ReleaseComObject(MtbApp); MtbApp = null;
使用C#的COM对象可能会非常棘手。特别是在你完成时释放它们。
请记住,一般来说不要加倍。不要做:
MtbApp.UserInterface.Visible = true;
相反:
Mtb.UserInterface MtbUI = null;
MtbUI = MtbApp.UserInterface;
MtbUI.Visible = true;
因此,MtbUI对象可以在以后释放。
没有“C#.NET”这样的东西。该语言只是C#,而框架就是.NET。 – 2010-07-01 19:25:33