Solved

Error checking

Posted on 2000-03-16
3
181 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now