Solved

Error checking

Posted on 2000-03-16
3
186 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 50 total points
ID: 2628300
Se my comment
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Facebook has became the #1 social media platform. People share many funny videos there, yet you don't know how to download them? Now you can download Videos from Facebook in just 3 simple steps.
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 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