0

I am making a simple appointment program and I want to have a back function that allows the user to return back to the previous line. For example, the user typed in the wrong year and wanted to change it so they would need to have a back button to type it again. I was wondering if this can be accomplished by an IF-ELSE statement, but maybe there are other ways to accomplish this? Below is a part of the program.

  MakeAppointment.
       DISPLAY " "
       DISPLAY "Year: "
       ACCEPT YEAR
       DISPLAY "Month: "
       ACCEPT MONTH
       DISPLAY "Day: "
       ACCEPT DAYS
       DISPLAY "NAME: "
       ACCEPT NAME-CAP
       MOVE FUNCTION UPPER-CASE(NAME-CAP) TO P-NAME
       DISPLAY "CONTACT NUMBER: "
       ACCEPT P-CONTACT
       WRITE AppointmentRec
           INVALID KEY DISPLAY "THIS SLOT IS NOT AVAILABLE."
       END-WRITE.

EDIT: Sorry if my question wasn't clear, I want the program to do is to go back to DISPLAY "Year: " from ACCEPT MONTH if the user was not satisfied with the year that they have typed. Though I already had an IF YEAR='B'EXIT PARAGRAPH but the program messes up during the ACCEPT NAME-CAP because I really need the name to always be capitalized. The date and contact are initialized as PIC X(). I'll also try and study Screen section and see if I can do it.

EDIT: New version of program

      MakeAppointment.
       DISPLAY " "
       DISPLAY "Year: "
       ACCEPT YEAR
       IF YEAR='B'
        EXIT PARAGRAPH
       ELSE
        DISPLAY "Month: "
        ACCEPT MONTH
        IF MONTH='B'
        EXIT PARAGRAPH
        ELSE
         DISPLAY "Day: "
         ACCEPT DAYS
         IF DAYS='B'
          EXIT PARAGRAPH
         ELSE
          DISPLAY "NAME: "
          ACCEPT NAME-CAP
          IF NAME-CAP='B'
           EXIT PARAGRAPH
          ELSE
           MOVE FUNCTION UPPER-CASE(NAME-CAP) TO P-NAME
           DISPLAY "CONTACT NUMBER: "
           ACCEPT P-CONTACT
           IF P-CONTACT='B'
            EXIT PARAGRAPH
           ELSE
            WRITE AppointmentRec
             INVALID KEY DISPLAY "THIS SLOT IS NOT AVAILABLE."
            END-WRITE
           END-IF
          END-IF.
  • Well an alternative to a large `IF-ELSE` statement is the `EVALUATE-WHEN`. But I am clueless of what do you have in mind or what you are trying to accomplish. – SNR Feb 14 '22 at 11:26

3 Answers3

3

You cannot achieve what you want with a simple DISPLAY/ACCEPT coding.

You really need to us a "SCREEN SECTION" which will allow you to display basic form type screens which will allow the user to tab between fields before entering the completed form.

See the documentation here: https://gnucobol.sourceforge.io/HTML/gnucobpg.html#SCREEN-SECTION

and A good tutorial here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
James Anderson
  • 27,109
  • 7
  • 50
  • 78
0

a simple GO TO statement to the MakeAppointment label can do the trick,

..else
    DISPLAY 'confirm year(y/n)? ' year
    ACCEPT ans
    if ans = 'n'
       go to MakeAppointment
    end-if 
    DISPLAY "Month: "... 
Roie
  • 132
  • 1
  • 4
0

If i understand your question right, than you want that a user can enter a number (year) and maybe she is disappointed with her entered number. If she is, she should be able to try it again.

Try this:

asking section.
  move space to user_input
  perform asking_year until user_input = "y"
  exit.
  
asking_year section.
  DISPLAY "year?"
  ACCEPT year
  DISPLAY "Did you want to set the year to:"
  DISPLAY year
  DISPLAY "(y for yes, anything else for no)"
  ACCEPT user_input
  exit.
robni
  • 904
  • 2
  • 6
  • 20