stop program crashing (data types)

i have a problem when ever i enter an incorrect data type using readln, like a letter in an integer variable or too many characters in a small string the program crashes is there a way to stop this?

Comments

  • : i have a problem when ever i enter an incorrect data type using readln, like a letter in an integer variable or too many characters in a small string the program crashes is there a way to stop this?
    :
    You can take all your input as strings and convert them to integers. The strings can be tested for illegal characters and then converted if they're clean. Or, if your compiler can use try..except blocks, use those. As far as the short strings thing goes, I'd recommend just using type string instead of those fixed length structures. Those get kinda messy in a strongly typed language like Pascal, and were actually more useful in days gone by when we had to squeeze everything into a small memory model.
  • : : i have a problem when ever i enter an incorrect data type using readln, like a letter in an integer variable or too many characters in a small string the program crashes is there a way to stop this?
    : :
    : You can take all your input as strings and convert them to integers. The strings can be tested for illegal characters and then converted if they're clean. Or, if your compiler can use try..except blocks, use those. As far as the short strings thing goes, I'd recommend just using type string instead of those fixed length structures. Those get kinda messy in a strongly typed language like Pascal, and were actually more useful in days gone by when we had to squeeze everything into a small memory model.
    :

    What about this?

    {$I-}
    Repeat

    Gotoxy(x1,y1);
    Cleol;
    Readln(Var)
    until (IOResult=0 ) and (Var in VarCheck);

    {$I+}
Sign In or Register to comment.

Howdy, Stranger!

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

Categories