GUI ScreenIO for Windows

 ScreenIO.com


Modular programming model using subroutines

We generally code GUI ScreenIO applications using a separate subroutine for each panel. 

Modularizing your software this way makes each module simpler and easier to debug, plus it's a snap to to reuse panels from several places in a large application. 

The logic is identical to the annotated version, except that we broke the application into subroutines instead of PERFORMed paragraphs.

Main Program

As you can see, the main program is trivial.  All it does is open the main window, call the subroutine that handles the first application panel, and when control returns, it closes the main window and quits. 

 IDENTIFICATION DIVISION.
 PROGRAM-ID. SAMPLE.
 DATE-COMPILED.
* ------------------------: GUI ScreenIO Sample Application.
 ENVIRONMENT DIVISION.
 CONFIGURATION SECTION.
 SOURCE-COMPUTER. IBM-PC.
 OBJECT-COMPUTER. IBM-PC.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
* ------------------------: Panel copybooks.
     COPY SAMPMAIN.
*
PROCEDURE DIVISION.
*
* ------------------------: Create the main window.

     PERFORM DISPLAY-MAIN-PANEL.

* ------------------------: Call the subroutine that handles SAMPLE1

     CALL 'PSAMPLE1'.
*
* ------------------------: Close the main before doing a STOP RUN

     SET SAMPMAIN-DO-CLOSE TO TRUE.
     PERFORM DISPLAY-MAIN-PANEL.
     STOP RUN.


 DISPLAY-MAIN-PANEL.
* ------------------------: Update the application's main panel.

     CALL 'GS' USING SAMPMAIN-1
                     SAMPMAIN-2
                     SAMPMAIN-3
                     SAMPMAIN-4.


Subroutine for SAMPLE1

As with the main program, the subroutine that handles panel SAMPLE1 is almost trivial.  The nice thing about the modular approach to system design is that it's easy to debug small modules like this. 

It's also easy to use them from other places in your application because all of the panel-specific logic is encapsulated in the subroutine.  Once the subroutine is debugged, you can reuse it from anywhere without worrying about the details.

You'll also notice that all of your subroutines tend to be very similar in structure.  This makes it easy to develop and maintain systems, since the general logic of handling your user interface (e.g., the panel) is standardized.

 IDENTIFICATION DIVISION.
 PROGRAM-ID. PSAMPLE1.
 DATE-COMPILED.
* ------------------------: GUI ScreenIO Sample Application.
 ENVIRONMENT DIVISION.
 CONFIGURATION SECTION.
 SOURCE-COMPUTER. IBM-PC.
 OBJECT-COMPUTER. IBM-PC.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
* ------------------------: Panel copybooks.
     COPY SAMPLE1.

PROCEDURE DIVISION.

 DISPLAY-SAMPLE1.
* ------------------------: Loop to handle the base panel.

     SET DISPLAY-IN-MESSAGEBOX-ON TO TRUE.
*
     PERFORM WITH TEST AFTER
         UNTIL SAMPLE1-EVENT-CLOSE-WINDOW
            OR SAMPLE1-EVENT-CLOSE-AND-STOP
            OR SAMPLE1-FILE-EXIT

       CALL 'GS' USING SAMPLE1-1
                       SAMPLE1-2
                       SAMPLE1-3
                       SAMPLE1-4

* ------------------------: This just increments a counter that
*                         : shows how many times the panel has
*                         : been displayed.
 
       ADD 1 TO EDIT-CYCLE-COUNTER

* ------------------------: This portion of the performed loop
*                         : processes events that caused GUI
*                         : ScreenIO to return.

       EVALUATE TRUE

* ------------------------: Menu selection: File/Display Popup

         WHEN SAMPLE1-MENU-SHOW-POPUP
           CALL 'PSAMPLE2'

* ------------------------: Button pressed: Display Popup

         WHEN SAMPLE1-BUTTON-SHOW-POPUP
           CALL 'PSAMPLE2'

* ------------------------: Button pressed: Move data from one
*                         : edit control to another, then move
*                         : space to the first edit control.

         WHEN SAMPLE1-BUTTON-MOVE-1-TO-2
           MOVE EDIT-CONTROL-1 TO EDIT-CONTROL-2
           MOVE SPACE TO EDIT-CONTROL-1

* ------------------------: Button pressed: Display the text
*                         : from the "Message text" edit control
*                         : in a message box or in the status bar,
*                         : depending on a radiobutton.

         WHEN SAMPLE1-DISPLAY-MESSAGE
           MOVE MESSAGE-TEXT TO SAMPLE1-MESSAGE-TEXT
           IF DISPLAY-IN-MESSAGEBOX-ON
             SET SAMPLE1-MESSAGE-IN-MESSAGEBOX TO TRUE
           ELSE
             SET SAMPLE1-MESSAGE-BAR-BEEP TO TRUE
           END-IF

* ------------------------: Disregard all other events.

         WHEN OTHER
           CONTINUE

       END-EVALUATE

     END-PERFORM.

     GOBACK.


Subroutine for SAMPLE2

What can we say?  You can't have much less code than this!

 IDENTIFICATION DIVISION.
 PROGRAM-ID. PSAMPLE2.
 DATE-COMPILED.
* ------------------------: GUI ScreenIO Sample Application.
 ENVIRONMENT DIVISION.
 CONFIGURATION SECTION.
 SOURCE-COMPUTER. IBM-PC.
 OBJECT-COMPUTER. IBM-PC.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
* ------------------------: Panel copybooks.
     COPY SAMPLE2.

PROCEDURE DIVISION.

* ------------------------: Loop to handle the popup panel.
*
     PERFORM WITH TEST AFTER
         UNTIL SAMPLE2-EVENT-CLOSE-WINDOW
            OR SAMPLE2-EVENT-CLOSE-AND-STOP

       CALL 'GS' USING SAMPLE2-1
                       SAMPLE2-2
                       SAMPLE2-3
                       SAMPLE2-4

       EVALUATE TRUE

* ------------------------: Button pressed: Display text in
*                         : a message box.

         WHEN SAMPLE2-DISPLAY-MESSAGE
           SET SAMPLE2-MESSAGE-IN-MESSAGEBOX TO TRUE
           MOVE 'Sample messagebox.' TO SAMPLE2-MESSAGE-TEXT

* ------------------------: Disregard all other events.

         WHEN OTHER
           CONTINUE

       END-EVALUATE

     END-PERFORM.

     GOBACK.


© 2000-2019 Norcom, all rights reserved 

TOC

Send feedback to Norcom