Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error checking

Posted on 2000-03-16
3
Medium Priority
?
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 150 total points
ID: 2628300
Se my comment
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
In this article, I’ll show how research, determination, and use of modern technology helped me solve a DNA mystery.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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