Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Error Trapping

Hi all,

Can anyone help me with trapping error 106 at runtime with the readln command?

Rgds,
crashed

Comments

  • : Hi all,
    :
    : Can anyone help me with trapping error 106 at runtime with the readln command?
    :
    Hi crashed,

    excerpt from Turbo Pascal Help:

    "Read and ReadLn report this error if a numeric value read from a text file doesn't conform to the proper numeric format."

    Ergo, I suggest
    a) using (for testing/trapping only) not a numeric, but a string variable for reading data (this always works) and
    b) setting a breakpoint after reading from file this string. From the string's format You can know what's happening.

    Best regards,

    gyapesz


  • ThozzThozz Posts: 20
    Hi there!.

    Just try this:

    var
    x : integer;

    begin
    write('Type an integer: ');
    {$I-}
    readln(x);
    {$I+}
    if (IOResult = 0) then writeln('Ok, thanks!')
    else writeln('I have asked for an integer!!!');
    end.

    {$I-} turns off runtime error while reading from a file or from the keyboard!. If there is something bad, function IOResult results different to 0.
  • : Hi there!.
    :
    : Just try this:
    :
    : var
    : x : integer;
    :
    : begin
    : write('Type an integer: ');
    : {$I-}
    : readln(x);
    : {$I+}
    : if (IOResult = 0) then writeln('Ok, thanks!')
    : else writeln('I have asked for an integer!!!');
    : end.
    :
    : {$I-} turns off runtime error while reading from a file or from the keyboard!. If there is something bad, function IOResult results different to 0.
    :


    Do I need to USE any library???

    Thanks for your help.
    Crashed
  • ThozzThozz Posts: 20
    : Do I need to USE any library???
    No!. It runs under TP7 without using any library. I think it's the same under FPC.

Sign In or Register to comment.