home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
modula2
/
library
/
queuem2
/
getrange.mod
< prev
next >
Wrap
Text File
|
1989-08-02
|
4KB
|
120 lines
(* source: h:\modula\code\util\GetRange.MOD v1.0a revised: 88.06.20
author: G.Greene, AGCS D/429 (NS/TS), 312/681-7783 created: 88.06.20
function:
This is the implementation code for a module which exports procedures
which interact with the operator, prompting for numeric values which
must be constrained to specified ranges.
history:
88.06.20 1.0a initial release.
*)
IMPLEMENTATION MODULE GetRange;
FROM IO IMPORT (*PROC*) WrStr, WrCard, WrLn, RdCard,
WrInt, RdInt, RdReal;
(* Return as the function value a CARDINAL within the range specified by
the first and second parameters. The value to be returned is requested
interactively of the program's operator, using the prompt string specified
by the third parameter, and a display of the acceptable value limits.
*)
PROCEDURE GetLimitedCARDINAL (
(*in*) LowerLimit,
(*in*) UpperLimit: CARDINAL;
(*in*) PromptString: ARRAY OF CHAR ): CARDINAL;
VAR
InputValue: CARDINAL;
BEGIN
REPEAT
WrStr ( PromptString ); WrStr ( " [" );
WrCard ( LowerLimit, 1 ); WrStr ( ", " );
WrCard ( UpperLimit, 1 ); WrStr ( "]: " );
InputValue := RdCard ( );
WrLn;
UNTIL ( InputValue >= LowerLimit ) AND ( InputValue <= UpperLimit );
RETURN InputValue;
END GetLimitedCARDINAL;
(* [2]
source: h:\modula\code\util\GetRange.MOD v1.0a revised: 88.06.20 *)
(* Return as the function value an INTEGER within the range specified by
the first and second parameters. The value to be returned is requested
interactively of the program's operator, using the prompt string specified
by the third parameter, and a display of the acceptable value limits.
*)
PROCEDURE GetLimitedINTEGER (
(*in*) LowerLimit,
(*in*) UpperLimit: INTEGER;
(*in*) PromptString: ARRAY OF CHAR ): INTEGER;
VAR
InputValue: INTEGER;
BEGIN
REPEAT
WrStr ( PromptString ); WrStr ( " [" );
WrInt ( LowerLimit, 1 ); WrStr ( ", " );
WrInt ( UpperLimit, 1 ); WrStr ( ": " );
InputValue := RdInt ( );
WrLn;
UNTIL ( InputValue >= LowerLimit ) AND ( InputValue <= UpperLimit );
RETURN InputValue;
END GetLimitedINTEGER;
(* [3]
source: h:\modula\code\util\GetRange.MOD v1.0a revised: 88.06.20 *)
(* Return as the function value a positive REAL. The value to be returned is
requested interactively of the program's operator, using the prompt string
specified by the first parameter. The second parameter indicates whether
zero is an acceptable value: if is is FALSE, the value must be "strictly
positive" (i.e., non-zero).
*)
PROCEDURE GetPositiveREAL (
(*in*) PromptString: ARRAY OF CHAR;
(*in*) ZeroAllowed: BOOLEAN ): REAL;
VAR
Value: REAL;
Valid: BOOLEAN;
BEGIN
WrStr ( PromptString ); WrLn;
REPEAT
CASE ZeroAllowed OF
FALSE:
WrStr (
" ... your answer must be a strictly positive real value: " );
Value := RdReal ( ); WrLn;
Valid := Value > 0.0;
|
TRUE:
WrStr ( " ... your answer must be a positive real value: " );
Value := RdReal ( ); WrLn;
Valid := Value >= 0.0;
END; (* CASE ZeroAllowed *)
UNTIL Valid;
RETURN Value;
END GetPositiveREAL;
END GetRange.