0

I'm trying to write a simple .com file that will give the user a choice to open files from a pick list. It opens the files fine when you select the number, but if you select an invalid choice, it should loop you back to the pick list. That is not working.

I've been looking at the OpenVMS User's Manual but have been unable to resolve this.

$! CHOICE.COM
$! Test file to offer choice to open one of two files
$!
$ ON WARING THEN EXIT
$ HOME:
$ WRITE SYS$OUTPUT “”
$ WRITE SYS$OUTPUT “1 – FILEA”
$ WRITE SYS$OUTPUT “2 – FILEZ”
$ WRITE SYS$OUTPUT “”
$ WRITE SYS$OUTPUT “”
$ INQUIRE P1 “Enter the number of the file to open or type X to exit:”
$ IF P1.EQS.”1”
$              THEN
$                   @FILEA.COM
$                    ENDIF
$ IF P1.EQS.”2”
$              THEN
$                   @FILEZ.COM
$                    ENDIF
$ IF P1.EQS.”X”
$              THEN
$                   EXIT
$ IF P1.EQS.””
$              THEN
$                   WRITE SYS$OUTPUT “Invalid Choice – try again!”
$                   WAIT 0:0:5
$                   GOTO HOME
$   ENDIF
$ !

I expect an invalid choice to return the user to HOME:

DCL Newb
  • 3
  • 2
  • `ON WARING`? I don't think DCL supports blenders. Your only _wrong_ choice is `""`. If you changed the code to use `if`/`then`/`else` to check the input the final `else` would be all the choices that you don't handle. – HABO Jul 25 '19 at 13:22
  • Alternatively, each of the `if` blocks could transfer control when it is finished, e.g. `$ goto Done` with a label `$ Done: exit` added at the end of the file. Or `$ goto Home` if that is appropriate. In either case, the final `if` disappears. If you wind up falling through all of the good choices, whatever is left is bad. – HABO Jul 25 '19 at 13:30

1 Answers1

0

OK, with a little help from a programmer, I have the answer.

$! CHOICE.COM
$! Test file to offer choice to open one of two files
$!
$ ON WARING THEN EXIT
$ HOME:
$ WRITE SYS$OUTPUT ""
$ WRITE SYS$OUTPUT "1 - FILEA"
$ WRITE SYS$OUTPUT "2 - FILEZ"
$ WRITE SYS$OUTPUT ""
$ WRITE SYS$OUTPUT ""
$ INQUIRE P1 "Enter the number of the file to open or type X to exit:"
$ IF P1.EQS."1"
$ THEN
$   @FILEA
$   EXIT
$ ENDIF
$ IF P1.EQS."2"
$ THEN
$   @FILEZ
$   EXIT
$ ENDIF
$ IF P1.EQS."X" THEN EXIT
$ WRITE SYS$OUTPUT "Invalid Choice - try again!"
$ WAIT 0:0:5
$ GOTO HOME
DCL Newb
  • 3
  • 2
  • 1
    Aside: It is considered a best practice to have a single exit, i.e. add `$ Done: exit` at the end of the procedure and have all of the code `goto` there. That way you can add code to handle cleanup and the like later without trying to hunt down and understand every `exit` sprinkled through the code. It isn't a hard and fast rule, e.g. it may make sense to have a `$ Failed:` exit that logs some information before terminating. `WARING` or `WARNING`? – HABO Jul 25 '19 at 14:27