Solved

Error checking

Posted on 2000-03-16
3
184 Views
Last Modified: 2010-04-16
In this program I'm writing, a user is prompted to enter an integer. (variable name WIDTH) The user is then prompted for the HEIGHT. (another integer)

What should I do when the user enters something that is not a integer? (ie: a character.) Currently I receive a runtime error. (#106 invalid numeric format.)

I have tried using the VAL command, but it does not want to work if the user enters something like "x"

I'd apprecate any help.

thanks
0
Comment
Question by:Kory
  • 2
3 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 2627100
The best option is to use VAL.

Why doesn't that work for you?

I think you first need to declare a string variable. Use this when you ask for the integer values

VAR
   Height, Width, ErrorCode : Integer;
   Question : String[5];

Begin
errorcode=99;

Repeat
Write('Height : ');
Readln(Question);
Val(Question, Height, ErrorCode);
Until ErrorCode=0;


errorcode=99;

Repeat
Write('Width : ');
Readln(Question);
Val(Question, Width, ErrorCode);
Until ErrorCode=0;

I'm not sure if my syntax is exactly correct. I'm typing it directly into this box.

Try to make use of the errorcode variable. It gives you "the result" of the VAL-procedure.

Regards
Batalf

0
 
LVL 3

Expert Comment

by:vikiing
ID: 2628269
>>I'm not sure if my syntax is exactly correct

Batalf: that's the proper syntas, and it works that way.

Kory: you don't have another option; Val() procedure is the only thing you have to do what you need.

I can add that variable "errorcode" will contain the position of the offending byte, i.e.:

     S:='1234X'; Val(S, I, ErrorCode);

in this example, ErrorCode will return 4 ('cause the 4th byte was unaccepted).

0
 
LVL 32

Accepted Solution

by:
Batalf earned 50 total points
ID: 2628300
Se my comment
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
SEO can be a real minefield to navigate, but there are three simple ways to up your SEO game just be re-assessing your content output.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question