Minitab 帮助文件在一定程度上提供了关于该主题的支持,并且所有示例均使用 VB。我是 .NET 的新手,但我很快就学会了。它在命令的语法中有所体现。
他们在 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 执行 Minitab 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3160767/