Operating System - OpenVMS
1833130 Members
3426 Online
110051 Solutions
New Discussion

How do you set up CNTRL Y that has a normal exit when operator executes CNTRL Y

 
SOLVED
Go to solution
Kenneth Toler
Frequent Advisor

How do you set up CNTRL Y that has a normal exit when operator executes CNTRL Y

This is what I have tried:

set control=y

...

on control_y then goto end

...

end:

exit

Why does this not work?

Shouldn't "on control_y then goto end" work no matter where I put it in the code?
2 REPLIES 2
Bojan Nemec
Honored Contributor
Solution

Re: How do you set up CNTRL Y that has a normal exit when operator executes CNTRL Y

Kenneth,

I dont know what you mean with
"Shouldn't "on control_y then goto end" work no matter where I put it in the code?"

A simple test procedure:

$ set control=y
$ write sys$output "before on_control"
$ wait 00:00:30
$ on control_y then goto end
$ write sys$output "after on_control"
$ wait 00:00:30
$ exit
$end:
$ write sys$output "ctrl y pressed"
$ exit

If you press before "after on_control" is displayed on the terminal the procedure will be terminated without going to the end label. If you press after the "after on_control" display, you will receive the "ctrl y pressed" on your terminal.

The on control command establish a handler for the , so the command will be executed only if you press after the on control command.

Bojan
John Gillings
Honored Contributor

Re: How do you set up CNTRL Y that has a normal exit when operator executes CNTRL Y

Kenneth,

Where doesn't it work?

DCL is interpretive, so the ON condition only takes effect AFTER it is executed. Unlike "ON condition", which is a "one shot", ON CONTROL_Y remains in effect until it's changed. Beware that this can get you into unbreakable loops. You should probably put another ON CONTROL_Y after label "end" if you want to do something other than loop back to the label.

BTW, I'd also recommend against using "end" as a label name. The DCL interpreter can get confused with labels that are the same, or even similar to, some DCL commands, ESPECIALLY "structural" commands like IF, THEN, ELSE, ENDIF, SUBROUTINE, RETURN, EXIT etc...

Note that MOST of the time this doesn't matter, but in obscure cases it's been known to cause trouble, so it's just a good programming practice to avoid the possibility.
A crucible of informative mistakes