TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 70


TURBO-LESSON 15:  INTERACTIVE SCREEN HANDLING

OBJECTIVES - In this lesson, you will learn about:

1.  Setting up a Data Entry Screen
2.  Being nice to users - ClrScr
3.  Getting around the screen - GotoXY
4.  Screen messages and accepting user input


1.  Setting up a Data Entry Screen.

For most computer processing applications you will need to 
provide for entry of data.  This is one of the points where your 
programs interact with the person using the program.

How your programs are viewed by those using them will depend on 
how well you manage the user-computer interaction on the screen.

In this lesson you will try some of the basic techniques of 
screen handling for data entry.

##### DO:

Run PROG15.

Take a look at the program to see how this screen was produced.

##### DO:

Experiment with PROG15.

Run the program after each of the following:

(1)  Add or delete spaces in the WriteLn statements to move the 
various items.

(2)  Line the prompts up on the left.  You may want to keep the 
colons in a vertical column after you move the prompts.

(3)  In the main program, add two more statements:
       Print_Entry_Screen;
       Print_Entry_Screen;

TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 71


2.  Being nice to users - ClrScr.

Pascal provides a predefined procedure to clear the screen.  

Screen interaction will go smoother if unnecessary items are 
removed when no longer needed.  

##### DO:

(First, remove the 2 extra Print_Entry_Screen statements.  Notice 
that you could just load a new copy of PROG15.)

Add the following statement as the first statement in the main 
program:

WriteLn('This is something leftover from previous processing');

Run the program.

How does the data entry screen look now?

This problem was not apparent before, because the screen was 
cleared before the program executed.  The message you just added 
makes the situation more realistic - there are often things left 
on the screen that need to be cleared.



The procedure, ClrScr, will clear the screen.

Where should you put ClrScr, in the main program, or in the 
procedure?  

Right!  In the procedure, because clearing the screen is really 
just a part of printing the entry screen.

##### DO:

At the beginning of the Procedure, Print_Entry_Screen, add:

ClrScr;

Run the program.   Is the "leftover" message gone?

NOTE: YOU SHOULD ALWAYS CLEAR THE SCREEN AS NEEDED.  EARLIER 
      VERSIONS OF TURBO CLEARED THE SCREEN AT THE BEGINNING OF 
      THE PROGRAM, BUT THAT IS THE TYPE OF THING YOU SHOULD NOT 
      DEPEND ON.  WHAT IF THE NEXT VERSION CHANGES?  

TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 72


3.  Getting around the screen - GotoXY.

Cursor positioning is done with the predefined procedure, GotoXY.

To find out how it works, try PROG15A.

##### DO:

Examine PROG15A, then run it a few times using the following 
values for X and Y:
                    X   Y
                    1  20
                   40   1
                   70  23

Does GotoXY work the way you expected?  

If that is the way you expected it to work, no problem.

If you, like me, find that X and Y seem to be reversed, you can 
either learn to use GotoXY as is, or write a procedure to make it 
work the way you want it to!  

##### DO:

Add the following procedure before the main BEGIN END block:

PROCEDURE Locate(X, Y : Integer);

BEGIN
  GotoXY(Y, X);  { Note the reversed Y, X here }
END;

Also change the GotoXY(X, Y) statement in the main program to:

Locate(X, Y);

Run the program several times using the values: 
                  X    Y
                  1   50
                 10    1
                 23   70

My own choice is to use GotoXY as is, but if you work in both 
Pascal and Basic at the same time, you might want some procedure 
like Locate, to make the cursor positioning work the same in 
both.  

TURBO-LESSONS - A Pascal Tutorial        Version 1.01    Page 73


4.  Screen messages and accepting user input.

##### DO:

Examine PROCEDURE Get_First_Name in PROG15B.

Notice the use of GotoXY(13,3) to position the cursor next to the 
first name prompt on the screen.

Read(First_Name) is used instead of ReadLn.  Read and ReadLn will 
be contrasted and explored in a later lesson.  For now, just note 
that the procedure works.

##### DO:

Run PROG15B.

I hope you got the name right.  No second chance here!

Unfortunately, mistakes are made in data entry, and you must 
provide a convenient way to correct them.

##### DO:

Look at FUNCTION OK in PROG15C.

Also notice how PROCEDURE Get_First_Name has been changed to use 
the information provided by FUNCTION OK.

The user can now correct typing mistakes before going on.

PROGRAMMING NOTE: OBSERVE THAT FUNCTION OK MUST BE DECLARED 
                  BEFORE PROCEDURE GET_FIRST_NAME SINCE THE 
                  PROCEDURE USES THE FUNCTION.  

##### DO:

Run the program, entering a few wrong names of different lengths 
before entering the correct name (your name?)

Do you detect a problem?  There are screen leftovers again!  

There is another procedure, ClrEol, which clears from the cursor 
position to the end of the line.

##### DO:

Insert the statement:   ClrEol;

after the GotoXY(1,23) statement in FUNCTION OK and after the 
GotoXY(13,3) statement in PROCEDURE Get_First_Name.  

Run the program again, testing for leftovers.  Enter several 
names of different lengths again.

How's that?    You're on your way toward friendly input screens!


