Solved

Error checking

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Title # Comments Views Activity
TClientSocket.SendStream is slow... 2 970
Indy TIdHTTP POSTs getting slow responses 6 1,063
Pascal equivalent of VB Select/case 3 343
add combobox item based on numbers 9 154
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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