If you want to receive a message when a data table changes, use the Subscribe message. For example, you might want a message sent to the log when columns are added or deleted.
dt << Subscribe( "name"(<"client">), On Delete Columns | On Add Columns | On Add Rows | On Delete Rows | On Rename Column | On Close | On Save | On Rename ( function ) );
dt << Unsubscribe("keyname", On Delete Columns | On Add Columns | On Add Rows | On Delete Rows | On Close | On Col Rename | All);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
delRowsFn = Function( {a, b, rows},
dtname = ( a << Get Name());
Print( dtname );
Print( b );
Print Matrix( rows );
);
addRowsFn = Function( {a, b, insert},
dtname = ( a << Get Name() );
Print( dtname );
Print( b );
Print( insert );
);
dt << Subscribe( "Test Delete", onDeleteRows( delRowsFn, 3 ) );
dt << Subscribe( "Test Add", onAddRows( addRowsFn, 3 ) );
Subscribe to Data Table List() subscribes to a list of data tables to be notified when a new data table has been added or closed. The following example shows how to subscribe and unsubscribe:
f2 = Function( {x}, Show( x ) );
Show( Subscribe to Data Table List( "My Data", OnClose( f2 ) ) );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
Wait( 2 );
Close( dt );
Show( Unsubscribe to Data Table List( "My Data" ) );
Subscribe to Data Table List( "My Data", OnClose( f2 ) ) = "My Data";
x = Data Table( "Big Class" );
Unsubscribe to Data Table List( "My Data" ) = Empty();
If Subscribe is called with an empty application name, JMP generates a unique name that is returned to the caller. In the following example, appname2 is subscribed to the data table as a client.
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
appname1 = dt << Subscribe( "", On Close( Print( "Closing Data Table" ) ) );
appname2 = dt << Subscribe(
""( "client" ),
On Close(
Function( {dtab},
dtname = ( dtab << Get Name() );
Print( dtname );
)
)
);
dt << Unsubscribe( appname1, On Close );
dt << Run Script( "Distribution" )