14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

494 Extending JMP Chapter 14<br />

OLE Automation<br />

through Visual Basic and using Visual C++ with MFC. It also contains details for the methods and<br />

properties that JMP exposes to automation clients like Visual Basic and Visual C++<br />

The JMP\10\Samples\Automation folder contains several example Visual Basic .Net, Visual C# .Net, and<br />

Visual C++ .Net programs that automate features in JMP.<br />

Automating JMP through Visual Basic<br />

Starting a JMP Application<br />

The first step in automating JMP is to start it up. However, it’s important to look at the resources available<br />

to help you with the JMP methods and properties. JMP provides a type library that allows automation<br />

controllers like Visual Basic (VB) to display a list of the methods and properties that JMP exposes, along<br />

with parameters that the methods require. This library is called JMP.TLB.<br />

There are two steps to make the JMP type library available to VB.<br />

1. Select Project > References in VB. A list of applications that are known to VB appears. If JMP is not<br />

in that list, select Browse. A file window asks you to locate a .tlb (Type library) file. Find the icon for<br />

the JMP type library in the JMP directory. Select this library and click OK.<br />

2. Open the object browser by selecting View > Object Browser in VB. Select JMP from the drop down<br />

list box.<br />

Now you can see the JMP automation classes and constants. You can now select a class, and the methods<br />

available to that class appear in the right list box for the object browser. If you select a method, a short helper<br />

string appears at the bottom of the window. This string lists the parameters for the method. Constants are<br />

used when methods require a restricted set of parameters, typically denoting a specific action.<br />

Now that you have access to the type library information, write the necessary code to instantiate JMP. This<br />

is done with CreateObject. In global declarations for the VB project, create a variable of type<br />

JMP.Application. This is done as:<br />

Dim MyJMP As JMP.Application<br />

Now dimension some other variables. Good examples are DataTable, Distrib, Oneway, and JMPDoc.<br />

These are specified with JMP.DataTable, JMP.Distribution, JMP.Oneway, and JMP.Document<br />

respectively.<br />

To create a JMP session, make it visible, and load a data table, add the following code to your VB script.<br />

Dim JMPDoc As JMP.Document<br />

Set MyJMP = CreateObject("JMP.Application")<br />

MyJMP.Visible = True<br />

Set JMPDoc = MyJMP.OpenDocument("C:\Program Files\<strong>SAS</strong>\JMP\10\Samples\Data\Big<br />

Class.jmp")<br />

The Dim statement indicates the type of variable. This declaration should go in the general declarations<br />

section of your VB project, though. If you do not do this, the JMP objects are destroyed when the variable<br />

goes out of scope at the end of the procedure.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!