Hello, I'm looking at a sample program included with JMP 11:
C:\Program Files\SAS\JMP\11\Samples\Automation\Visual Basic Samples\Data Table .NET\datatab.vb
Since I don't have Visual Studio (just Excel), I opened "datatab.vb" with Notepad and attempted to translate the "Subset_Click" procedure from Visual Basic (VB) to Visual Basic for Applications (VBA). Please see the code example below.
I have a few questions:
- Why does "doc = app.OpenDocument(fname)" cause a run-time error "Object variable not set"?
- How do the datatable subset methods work? I can see these in the Excel VBA Object Browser, but there's not much detail.
- How is the datatable handle used?
Thanks for your help.
'--------------------------------------------------------
'Subset bigclass by Weight and Height
'Save new datatable handle in NewDT, then save table to disk as subset.jmp
'--------------------------------------------------------
Sub Subset()
Dim app As JMP.Application
Dim doc As JMP.Document
Dim dt As JMP.DataTable
Dim newDT As JMP.DataTable
Dim dtDoc As JMP.Document
Dim dir As String
Dim fname As String
'Start JMP
Set app = CreateObject("JMP.Application")
app.Visible = True
'Get data table
dir = "C:\Program Files\SAS\JMP\11\Samples\Data\"
fname = dir & "Big Class.jmp"
doc = app.OpenDocument(fname)
dt = doc.GetDataTable
'Subset data
dt.Activate
dt.SubsetSetRandomSelection(2, False)
dt.SubsetStratifyAddColumn ("age")
dt.AddToSubList ("Name")
dt.AddToSubList ("Weight")
dt.AddToSubList ("Height")
newDT = dt.Subset
dtDoc = newDT.Document
dtDoc.SaveAs ("C:\JMP\subset.jmp")
End Sub
'--------------------------------------------------------