Interested in knowing if there is a method to automatically close a window containing a report when the datatable is closed, specifically using the "<< On Close" message? For example, I create a distribution from a datatable and add the results to a window along with some other important info. If the user closes the data table, I would like to perform some actions on the window. The following demonstrates:
Names Default To Here(1); dt = Open("$SAMPLE_DATA/Big Class.jmp"); VLB = VlistBox( Distribution(Column(:Age, :Weight)); ); win = New Window("Results", TextBox("Other things"), VLB ); dt << On Close( Show("Close script activated"); //this line is executed... VLB << Delete Box(); //...but not this one or any following it. Show("Remainder of script is not run..."); );
Using the "<< On Close" message would seem to be the answer, but I can't get it to work yet. When I close the table dt, the first line of the on-close script executes, but not the remainder. I get a message indicating other report windows are open and if I want to close them (clicking "Close All" closes the entire result window, not just the distribution), and finally a message asking to save ("No"). My suspicion is that when the "X" is clicked to close the table, my reference to VLB is deleted before the On-Close script can be executed.
I realize I could create a report of the distribution and put that in my window instead, but then it would be static, which I do not want.
I think your script is correct, and it runs on Windows in 14.3; what version of JMP are you running?
Might have to go through tech support. Probably a difference in the order things happen on the two OSs.
https://www.jmp.com/support/help/14-2/subscribe-to-a-data-table.shtml might provide a different-enough variation of onClose to make it work; I think dt<<onClose is running when the data table window closes, while the subscription may run earlier, before the table's window closes.
I've used report<<onClose to close the dt, but that is the reverse of what you are doing.
Ok - sent message to tech support so hopefully there's a workaround. I was unaware of the "Subscribe" feature, so thanks for sharing that. Unfortunately that does not work on my system either, probably same underlying reason. Even running "Example 1" in the scripting index entry for Subscribe fails. I can think of a lot of past scripts where using that would have been helpful though.
@nikles First of all, thank you for such a great script to replicate the problem/question. It's very easy to see what you're asking.
Secondly, i have to admit that when i first copied your script to try it out, i didn't copy the first line Names Default to Here(1). It turns out, omitting that line causes your script to work the way you want it to. That could be a workaround if you don't need that line to limit the scope of your variables. (Note: it is certainly a best practice to use names default to here(), but here it is leading to some kind of scoping issue.)
Thirdly, i found the behavior to be consistent across Mac and Windows. (So, @Craige_Hales, did you happen to also omit Names Default to Here(1)?)
Fourthly, Craige suggested that dt << subscribe might be a possibility, but i wasn't able to get it to work, with or without Names Default to Here(1); I continue to see the message about other report windows being open and do i want to close them.
Finally, i am following up with our development team and see if this is something that should be addressed.
Thanks Audrey! good catch too, yes, I left it out. It probably makes sense that vlb is local to the script editor window, and not available when the data table's window is running the onClose. I think a request is to get a message in the log window about vlb being undefined in the table's context.
Thanks guys. Unfortunately I think I do need to use Names Default to Here(1) as this script is getting used within others, but this soln might be useful to others.
I was able to get it to work with the NDtH command by making my VLB reference a global. This is still not ideal, but offers some possibilities.
Names Default to Here(1); dt = Open("$SAMPLE_DATA/Big Class.jmp"); ::VLB = VlistBox( Distribution(Column(:Age, :Weight)); ); win = New Window("Results", TextBox("Other things"), ::VLB ); dt << On Close( Show("Close script activated"); ::VLB << Delete Box(); Show("Remainder of script..."); );
If there's a way to get the Subscribe feature working though, I'd love that. There's other actions I'd like to perform on my window when changes are made to the table. Thanks again.