Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Error correction for data types Posted by Qubik on 25 Jun 2003 at 9:19 AM
I am doing a small research on error correction for wrong data types and would like your contributions if any. What would you do to prevent your program from crashing when the user enters an alphabetic character instead of an integer.(more to come later)

Qubik
Report
Re: Error correction for data types Posted by Perran on 25 Jun 2003 at 9:59 AM
: I am doing a small research on error correction for wrong data types and would like your contributions if any. What would you do to prevent your program from crashing when the user enters an alphabetic character instead of an integer.(more to come later)
:
: Qubik
:
This has been covered several times on this board. The best thing to do [IMHO] is to PREVENT the user from entering the wrong type of data. This can be done by capturing individual keystrokes as CHARs and testing them for propriety BEFORE submitting them to processing routines. The easiest way to test them for propriety is use the "in" operator and have a set of proper keys. e.g. for numbers your set would be ['0'..'9', #08, #13] allowing for backspace and enter. So, you capture individual keystrokes and then construct a string AFTER testing for set membership. HTH
Report
Re: Error correction for data types Posted by Manning on 25 Jun 2003 at 1:58 PM
: I am doing a small research on error correction for wrong data types and would like your contributions if any. What would you do to prevent your program from crashing when the user enters an alphabetic character instead of an integer.(more to come later)

Like Perran, I prefer to just stop them from entering invalid data. A common thing for people new to the language is to use ReadLn() for everything. That's easy, but not safe. So instead I have a couple dozen input routines that have various uses. For example inputting a number that falls in between two values, a string that is a certain length or fits a certain pattern, etc..

In the end this way is more work, but for me always knowing the input is valid outweighs the extra coding required (especially since the routines are all generic and re-usable, so they only need to be written once).



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.