Minitab help files provide support on this subject to a limited extent, and all examples are in VB. I am new to .NET, but I'm picking it up pretty quickly. Its something in the syntax for the command.
They provide this example in 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"
and my code looks like this in C#
var MtbApp = new Mtb.Application();
var MtbProj = new Mtb.Project();
MtbProj = MtbApp.ActiveProject;
MtbApp.UserInterface.Visible = true;
MtbProj.ExecuteCommand(<command>);
what I'm expecting should happen is Minitab should open, and the command should execute. However, whats happening is that two instances of Minitab are being opened and neither are showing user interface, I have to find them in processes.
Assuming you've added the reference to Minitab COM, this should get you started:
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;
Using COM objects for C# can be tricky. Especially with releasing them when you are done.
Remember, as a general rule never double . Don't do:
MtbApp.UserInterface.Visible = true;
Instead:
Mtb.UserInterface MtbUI = null;
MtbUI = MtbApp.UserInterface;
MtbUI.Visible = true;
So, the MtbUI object can be freed later.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With