
==== Step 3:
Step Title     : Basic Input and Output..
File Name      : MP_3.txt
Author Note    : The better the interface, the better the program..
Example Source : none
Author         : Michael Preslar / E_Maus
Date           : September 27th, 1998
Length         : 8 pages
Layout         : - write / writeln
                 - read / readln
                 - Format codes for write / writeln
                 - Whats a good interface?
                 - Retrospect
====
Please refer back to "intro.txt" for complete documentation of copyrights,
and author information.

Step 3 Foreword
---------------
No matter how good a program is, if it has a bad user interface, it wont
be of much use. Nor will it be used much, for that matter. For instance..
Ive used the WildCat! bbs software for years. It is a wonderful engine that
has good file and message capabilities. But since the default menus suck,
and the way the software is laid out from a sysop's point of view, its not
used as much as it used to. More softwares have come along that have the same
capabilities, but are much easier to use. Ive had to modify my board so much
it doesnt even seem like WildCat! anymore. Ive basically changed the entire
user interface.

Whats an "interface"? If youre sitting at the main menu of your favorite
bbs, thatd be an interface. Its the way the program gets information from
you (input), and its also what the program writes to the screen (output).
The menu the bbs displayed for you is the output, while the command you
give it is the input.

In this lesson, were going to study basic pascal IO, and how to make an
interface thats comfortable for both the end-user and the host-user. Im
going to assume you already know previous lessons about variables, basic
program syntax, and arrays.

First and foremost, let me introduce you to a few friends of mine:
Read and readln, write and writeln. In mp_1.txt, you were shown these 4, but
without much detail. Since they are so simple, Im going to mix in a bit of
"programming theory", and try to explain my views of user-friendly interface.
Ill cover everything I can about these 4 without having to explain other
things.

  ======================== Write / Writeln =================================
Quite simply, these two just output something to the current output device.
For now, the only output device well concentrate on is the screen. The only
difference between the two when working with the screen is writeln adds a
CRLF after outputing to the screen. Write just outputs to the screen.

Some information about write/writeln.. It can output anything just so much
as its done correctly. Heres some examples:

var
    s: string;
    b: byte;
    b2:byte;
    ch:char;
    ch2:char;

valid:
writeln;
writeln('hi there!');
writeln('hi there!',s);
writeln('hi there!',b);
writeln('hi there!',ch,' ',s,b);
writeln('hi there!'+s);
writeln('hi there!'+s,ch+ch2);
writeln(b+b2);

invalid:
writeln('hi there!'+ch); or +b, or any other variable thats not a string.

To explain it in words.. As long as each item is seperated by a comma,
anything is valid.  However, you can use a plus sign (+) as long as the items
your adding are of the same type.

Take note of the next to last and last valid examples. Particularly "ch+ch2"
and "b+b2".. Whenever you add variables like this, they have to be of the
same type. If the types are number types, then the output will be the sum of
the two. If the types are either string or char, then write/writeln will
"concatenate" (add together) them. As in.. If "b" equals 1 and "b2" equals
2 then "write(b+b2);" would output "3". If ch equals "a" and ch2 equals "b"
then the output would be "ab".

Notice the single quotes around the "hi there!" in each of the above examples
If youre outputing something thats not a variable it must be enclosed in
single quotes.

And no, Non variables dont have to be the first thing in a write or writeln
statement.

Take a look at the first valid example.. "writeln;".. This is valid. You
dont have to actually output something. What this command would do is output
a carriage return (hitting the enter key) and nothing more.

  ============================ Read / Readln ==============================
Read and readln are almost as simple. Instead of output, they do input. Again
the only main difference between the two is that readln will output a carriage
return after it gets some input.

Examples:

var s:string;
    c:char;
    b:byte;

valid:
readln;
readln(s);
readln(c);
readln(b);
readln(c,s);

invalid:
readln(s,b);

Again, you dont have to pass a variable to read/readln. Without one, it would
be a "<more>" or "<hit a key>" type prompt. Again, you can pass multiple
variables.. BUT.. If you used different types, for example the invalid one,
the compiled program wont be able to tell what input goes in what variable.
Its up to you, the programmer, to do that. The invalid example will compile,
but I call it invalid since the values in the variables after the read/readln
wont be what youre looking for.

  ================= Format codes for write / writeln =======================
Take a look at these:

Example 1:     writeln('I am centered on the screen.':62);
Example 2:     write(1 / 3 :8:3);

Example 1:
 When writing text, you can add something like the above to the non-variable.
 What it does is places the end of the text (the period) 62 columns relative
 to where the cursor was before the write. Whats "relative"? Easy to under-
 stand, yet hard to describe.. <grin>.. Using the monitor for our definition,
 in standard 80x25 textmode. You know that your monitor can go across 80
 times and down 25. So "62 columns" is 62 moves to the right. "relative"
 would be the starting point. If your currently on colomn 1, and moved 62
 columns relative, youd end up on column 63.

Example 2:
 Now that weve covered what relative means, we can do this easily. This
 example will write the value of "1 / 3". The actual result would be in
 scientific notation, and would resemble "3.3333333333E-01". However, we
 want our programs to be at least humanly readable and understandable. Soo..
 write(1 / 3 :8:3); would write the result 8 columns relative, and to the
 third decimal place. Try it and see. Note that the second format code can
 be any number, however, it can only be used on real numbers.. Not integral
 numbers or any other types.

==== Whats a Good interface? ====
<Editor's Note: Since this section really didnt teach anything, it was moved
 to its own reference section.>

  ============================== Retrospect ================================
In this lesson, we studied read, readln, write, and writeln. Then we
covered format codes for write and writeln.

Learn anything new?