# How to abort evaluation when clicking CancelButton

If you run the following code you will notice that the evaluation continues in the following cells.

I want to abort evolution if CancelButton is clicked.

I tried to use FrontEndTokenExecute["EvaluatorAbort"] but it doesn't help:

DynamicModule[{yyyy = 2015, mm = 6, dd = 20}, DialogInput[Grid[{
{"Year:", InputField[Dynamic[yyyy], Number]},
{"Month:", InputField[Dynamic[mm], Number]},
{"Day:", InputField[Dynamic[dd], Number]},
{CancelButton[
DialogReturn[FrontEndTokenExecute["EvaluatorAbort"]]],
DefaultButton[DialogReturn[{Year = yyyy, Month = mm, Day = dd}]]}
}, Spacings -> {1, Automatic}, Alignment -> Left]]];

RandomReal[]


Any idea?

Thanks

• – Kuba Jan 12 '16 at 22:04

So far and with help of Kuba's links I got the following solution:

DynamicModule[{yyyy = 2015, mm = 6, dd = 20, cancel = False},

• It doesn't work on my machine (Mathematica 10.0.2.0,Windows 7). That is to say : RandomReal[]is still evaluated when I push the button "Cancel". (I must leave. Be back in 11 hours) – andre314 Jan 13 '16 at 7:18
• @andre you probably mean that you have RandomReal[] in the same cell that DynamicModule is. Then that's correct. – Kuba Jan 13 '16 at 7:42
• @andre and if you want to abort what is scheduled in current cell I'm afraid you have to use my stupid \$AssertFunction from linked thread. – Kuba Jan 13 '16 at 7:46
• @Kuba You are certainly right. I can reproduce what you say. Nevertheless. I thought that RandomReal[] was in a separate cell this morning. I have done a mistake somewhere else probably, but i can't reproduce it. – andre314 Jan 13 '16 at 18:36