14.03.2014 Views

Scripting Guide - SAS

Scripting Guide - SAS

Scripting Guide - SAS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

496 Extending JMP Chapter 14<br />

OLE Automation<br />

If a method produces an object that can also be automated, the object browser indicates this. For FitLine,<br />

the object browser specifies that the return type is As Fit.<br />

Since this is not a predefined type like short or BSTR, you can probably guess that this is an object. If you<br />

look farther down the object browser, you see Fit as an object type. This confirms that an object is<br />

produced, and also gives you the methods that Fit supports.<br />

Creating and Populating a Data Table<br />

New data tables can be created with the (appropriately named) NewDataTable method of the<br />

Application object. A filename is assigned at creation time. This method returns a column object, which<br />

must be retained as long as you want to add rows. By default, 20 rows are created. The SetCellVal<br />

method can be used to populate individual cells, and AddRows can be used to add rows as needed. Here is<br />

an example:<br />

Dim Col As Object<br />

Set DT = JMP.NewDataTable("C:\test.jmp")<br />

Set Col = DT.NewColumn("Col1", dtTypeNumeric, 0, 8)<br />

DT.Visible = True<br />

'You must add rows before populating the table with data<br />

DT.AddRows 20,0<br />

'Set Cell values to increments of 1.5<br />

For i = 1 To 10<br />

Col.SetCellVal i, i * 1.5<br />

Next i<br />

DT.Visible = False<br />

For i = 11 To 20<br />

Col.SetCellVal i, i * 1.5<br />

Next i<br />

DT.Visible = True<br />

'This adds 5 rows to the end of the table<br />

DT.AddRows 5, 0<br />

'This adds 5 rows after row 2<br />

DT.AddRows 5, 2<br />

'Now save the data table using the previously specified filename<br />

DT.Document.Save<br />

'If you wanted to create a subset of the table, with only rows 1-3<br />

'you could do the following<br />

'Note: you could also create subsets using specific columns by adding the<br />

'columns to a list using the AddToSubList member function of Datatable<br />

Dim NewDT As JMP.Datatable<br />

Dim DTDoc As JMP.Document<br />

DT.SelectRows 1,3<br />

Set NewDT = DT.Subset

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

Saved successfully!

Ooh no, something went wrong!