Board index » delphi » Avoid run-time error 106 and the like?

Avoid run-time error 106 and the like?

How can I avoid getting any errors when typing a non-numeric character into
a real or integer or byte?
 

Re:Avoid run-time error 106 and the like?


Quote
"M1ESK" <casual_man...@yahoo.co.uk> wrote:
>How can I avoid getting any errors when typing a non-numeric character into
>a real or integer or byte?

Input a string, convert the sting to integer, and check the
error code.  For instance, assuming that your Pascal has the val
function:

var s : string;
    x : real;
   code : integer;

repeat
  readln( s);
  val( s, x, code);
until code = 0; { input is a valid number}

Re:Avoid run-time error 106 and the like?


If you are using strictly standard Pascal, or want your code to be standard, you do
this by implementing your own number evaluator. They exist. Wirth (Jensen and Wirth)
published the entire routines to read and write reals in the "users manual and report".
Integers are fairly trivial.
Quote
M1ESK wrote:
> How can I avoid getting any errors when typing a non-numeric character into
> a real or integer or byte?

Other Threads