on stop anywhere do

nate100

Member
I am having a hard time getting the following to work:
on stop anywhere do:

message "stopped".

end.

Can somebody so a simple example from which when ctrl-c is pressed we get the "stopped message". I cannot get this message to come up is the problem. Say if I have the following loop:

for each so_mstr where so_doman = "nl1"
and so_nbr begins 's' no-lock:
display so_nbr. pause 1.
end.

Thanks in advance
 
This should work for CTRL-C:
Code:
ON CTRL-C ANYWHERE DO:
   MESSAGE "Stopped." VIEW-AS ALERT-BOX INFORMATION.
END.

Depending on your other code it may not work when the FOR EACH block is running so you could try:
Code:
 for each so_mstr where so_doman = "nl1"
                    and so_nbr begins 's' no-lock:
   IF KEYLABEL(LASTKEY) = "CTRL-C" THEN DO:
      MESSAGE "Stopped." VIEW-AS ALERT-BOX INFORMATION.
      LEAVE.
   END.
   display so_nbr. 
   pause 1. 
end.
 
Thank you for your answer. I tried this but was not successful in getting it to work. Can you please verify that it works on your end. It may be something with my setup so I like to confirm that what you have posted works correctly. Thanks
 
Here are 2 examples that work for the example shown:

Code:
read_loop:
for each so_mstr where so_doman = "nl1"
          and so_nbr begins 's' no-lock:
      inner_check:
    do on stop undo inner_check, leave inner_check:
        display so_nbr. 
         pause 1. 
          next read_loop.
    end.
    message "stopped" view-as alert-box.
    leave read_loop.
end.

Code:
outer_check:
do on stop undo outer_check, leave outer_check:
    read_loop:
    for each so_mstr where so_doman = "nl1"
              and so_nbr begins 's' no-lock:
        display so_nbr. 
        pause 1. 
     end.
   return.
end. 
message "stopped" view-as alert-box.
 
Thank you for your answer. I tried this but was not successful in getting it to work. Can you please verify that it works on your end. It may be something with my setup so I like to confirm that what you have posted works correctly. Thanks

I suspect that you are getting confused about the difference between a keyboard event which can be handled by a trigger (such as most control-key combinations) and a Progress condition which is handled by an ON condition, UNDO RETRY phrase in a block (where conditions are STOP, QUIT, ERROR and ENDKEY).

If your terminal defines control-c as the "interrupt" key then it will not be trappable as control-c and will instead act as STOP.
 
Back
Top