home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
modula2
/
mod2txt.arc
/
CHAP9.TXT
< prev
next >
Wrap
Text File
|
1987-03-25
|
4KB
|
124 lines
Chapter 9 - Example programs
The programs included in this chapter are intended to
be illustrations to you in how to write a complete program.
The programs are meant to be useful to you either as an
example of how to do some operation or as utility programs
for your general use.
TIMEDATE - Get Time and Date
This program calls one of the DOS functions to get the
current time and date. They are input as variables and can
be printed or displayed in any format you desire. Your
particular compiler may use a different format because there
is no standard in Modula-2. This is one of those areas that
will probably deviate from compiler to compiler. If you
study your documentation that came with your compiler, you
will find many other calls of this type described. This
program is meant to be an illustration of how to use this
particular call.
AREAS - Calculate Areas
This program is intended to be an illustration for you
of how to build up a larger program than any other that we
have examined up to this point. Notice that the main
program is simply one CASE statement that calls all of the
other procedures. It would be very simple to include the
code from each procedure right in the CASE statement and
have no procedure calls, but it would make the program very
difficult to understand. The way this example is coded, the
code is very easy to understand. After you understand the
main program, it is a very simple matter to visit each
procedure to see exactly what they do.
Notice how the menu works in this program. It reads
one keystroke and responds immediately making it a very
simple program to use.
PC - Printer Control
This is a very useful program that you can use to
control your printer. It is specifically set up for an
Epson RX-80, but you can modify the control characters to
set up your printer to whatever mode you desire. To use the
program, you call the program and supply a single letter
according to the displayed menu, and the program will send
the character or characters to the printer to select the
enhanced, compressed, or whatever mode you desire. If your
printer is located physically remote from you, you can use
this program to send a formfeed to the printer by selecting
the F option. If you have some longer control sequences to
send, you may want to store the values in a string and use a
Page 58
Chapter 9 - Example programs
loop to output the data until you come to an 0C character.
LIST - List Program File
If you ran the batch file named LISTALL as suggested at
the beginning of this tutorial to print out all of the
source files, you have already used this program. It is the
program that will list any ASCII file, adding line numbers,
page numbers, and the date and time, on the printer. It is
specifically designed to be a program listing utility. The
operation is very simple, and you should have no trouble in
understanding this program or what it does.
Additional programs will be given at the end of Part
III for your information. You will no doubt find additional
example programs in various books and periodicals and it
would be to your advantage to to spend some time studying
them as illustrations of both good and bad practices.
Page 59