How Do I Check For Valid Type? 
Author Message
 How Do I Check For Valid Type?

Hello Pascal Lovers....

I was just wondering if there's any way of checking for a valid variable
TYPE when prompting user for inputs?
Say... the user's supposed to key in a TYPE INTEGER but he keys in CHAR
instead... Because otherwise, Turbpo PAscal will return an invalid TYPE &
abort the program.

Be glad if anyone can help... Thanks in advance!

Junaidi



Wed, 18 Jun 1902 08:00:00 GMT  
 How Do I Check For Valid Type?

Quote:

>Hello Pascal Lovers....

>I was just wondering if there's any way of checking for a valid variable
>TYPE when prompting user for inputs?
>Say... the user's supposed to key in a TYPE INTEGER but he keys in CHAR
>instead... Because otherwise, Turbpo PAscal will return an invalid TYPE &
>abort the program.

>Be glad if anyone can help... Thanks in advance!

>Junaidi

The way I addressed the problem:

-read input using readkey character by character.
-ignore any irrelevant characters (if you are reading an integer, ignore all
but numbers and the '-' sign.  make sure you count how many minus signs were
read and discard all but the first one. it has to come before any of the
numbers, too)  term "irrelevant character" will be different, of course,
depending on the type you are reading (integer, real, string, etc)
-don't forget to echo all relevant characters to the screen and allow for
backspacing.

Nik.



Wed, 18 Jun 1902 08:00:00 GMT  
 How Do I Check For Valid Type?

Quote:
>You read the input either as a string, or a series of characters,
>then check if the input contains only  ['+','-'](['0' .. '9']),
>if yes then
>   convert
>else
>   do-something-else

Hi Guys,

Thanks for the advice(s)....

Uhh... One more thing. Suppose I do the above mentioned, how do I then
convert say.. a type char to type integer?

Thanx!



Wed, 18 Jun 1902 08:00:00 GMT  
 How Do I Check For Valid Type?

Quote:

> >You read the input either as a string, or a series of characters,
> >then check if the input contains only  ['+','-'](['0' .. '9']),
> >if yes then
> >   convert
> >else
> >   do-something-else

Once you have the string, you could also pass it through the val() function to
verify that it's a valid number.

Quote:
> Hi Guys,

> Thanks for the advice(s)....

> Uhh... One more thing. Suppose I do the above mentioned, how do I then
> convert say.. a type char to type integer?

See above, but it takes string types, not single chars.

Quote:
> Thanx!

--
Scott Earnest            | SPAM protection in effect. Remove  |





Wed, 18 Jun 1902 08:00:00 GMT  
 How Do I Check For Valid Type?

Quote:
> Uhh... One more thing. Suppose I do the above mentioned, how do I then
> convert say.. a type char to type integer?

   The Ord function.


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. checking for correct data entry or preventing that it can be done

2. Overriding Type Checking for Pointers

3. checking a corrupted database typed file

4. 'Metafile is not valid'

5. Find out if a string is valid filename with path

6. "Index not valid"

7. Textbackground still valid after deleted!!

8. VALID/INVALID INPUT

9. Help to verify valid source

10. TDBImage bitmap image not valid??

11. changing real type data to word type

12. Money field type same as Currency data type??

 

 
Powered by phpBB® Forum Software