JSL code to clear selected data table contentsI'm trying to do something that I think should be very easy to accomplish, but I can't find the JSL instruction that will let me. Basically, after selecting various columns and rows I want to delete the contents of the selected cells, not the entire column or row. I can do this manually, but can't find the JSL command to do so. Any suggestions would be appreciated.
E.g.,
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Select Rows( [5, 7, 8, 10] );
Column ( "name" ) << Set Selected ( 1 );
Column ( "sex" ) << Set Selected ( 1 );
Now delete the contents of the selected cells.
Thanks.
Re: JSL code to clear selected data table contents<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />There's a difference between operating system standards here. Windows uses Edit->Clear and the Mac uses Edit->Delete.
So, to make a script robust to either you'll need to use:
If(Host is( Windows ),
Main Menu( "Clear" ), //Windows
Main Menu( "Delete" ) //Mac
);
-Jeff
Re: JSL code to clear selected data table contentsThanks folks for your suggestions,
Nice to see several options. I was thinking there should be a typical command I could call as suggested by MS ( Note: actual command is Main Menu("Clear");, not Main Menu("Delete"))
Re: JSL code to clear selected data table contentsMany thanks! Fewer characters is good, especially with my typing . . .
Re: JSL code to clear selected data table contentsNice function Ian! To simplify it further you could avoid treating different data types separately by using Empty(). It works for both Numeric and Character columns.
For(c = 1, c <= N Items(selCols), c++, Column(dt, selCols[c])[selRows] = Empty());
Re: JSL code to clear selected data table contentsA simple but potentially risky method is to use MainMenu() to invoke the Delete command in the Edit Menu. It is risky because it will delete anything that is selected in the active window. So in a complex script, make sure to keep track of what window that will be on top when the command is run.
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Select Rows([5, 7, 8, 10]);
Column("name") << Set Selected(1);
Column("height") << Set Selected(1);
dt << Bring Window To Front;
Main Menu("Delete");
Re: JSL code to clear selected data table contentsSomething like this:
NamesDefaultToHere(1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
// Set up a selection of cells
dt << Select Rows( [5, 7, 8, 10] );
Column (dt, "name" ) << Set Selected ( 1 );
Column (dt, "sex" ) << Set Selected ( 1 );
// Function to set currently selected cells to '.' or ""
clearSelectedCells =
Function({dt}, {Default Local},
selCols = dt << getSelectedColumns;
selRows = dt << getSelectedRows;
for(c=1, c<=NItems(selCols), c++,
dType = Column(dt, selCols[c]) << getDataType;
if (dType == "Numeric",
Column(dt, selCols[c])[selRows] = .
,
Column(dt, selCols[c])[selRows] = ""
);
);
);
// Use the function
clearSelectedCells(dt);