home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.pascal:7978 comp.os.msdos.programmer:11938
- Newsgroups: comp.lang.pascal,comp.os.msdos.programmer
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!purdue!yuma!hallch
- From: hallch@CS.ColoState.EDU (christopher hall)
- Subject: Re: Case/readln Question
- Sender: news@yuma.ACNS.ColoState.EDU (News Account)
- Message-ID: <Jan09.042742.40406@yuma.ACNS.ColoState.EDU>
- Date: Sat, 09 Jan 1993 04:27:42 GMT
- References: <1993Jan6.004700.207@sinus.stgt.sub.org>
- Nntp-Posting-Host: beethoven.cs.colostate.edu
- Organization: Colorado State University, Computer Science Department
- Lines: 39
-
- In article <1993Jan6.004700.207@sinus.stgt.sub.org> stefan@sinus.stgt.sub.org (Stefan Bechtold) writes:
- >... text deleted ...
- >What I want to do:
- >I want to control 15 numbers by a case-statement (so I do have to use
- >integer, doesn't I ?), but also want to control all other chars typed in
- >(so that the program doesn't exit but prints an error message.)
- >
- >Do you have any solution ?
-
- Maybe. I did something similar to this with a file name entry box. What
- you might try doing is reading the command in character by character as
- you are already doing it. Then, check the character and make sure that
- it is a number. If it is then append it to a string which you will later
- convert to your number. If it isn't then check if it is a backspace or
- a carriage return. For a backspace you need to cut the last character off
- of your storage string (provided there is one) and redraw the number. If
- it is a carriage return then check that your string is a valid number (by
- converting it to an integer with the VAL function.) Once you know the
- person has entered a valid number you can convert it to an integer (although
- you already did in order to check it) and VOILA you have your menu
- selection without a problem.
-
- Let me know if this is what you wanted. There is room for improvement but
- I have given you a general way to do this. I still remember the first time
- that I asked my parents to test a program for me and when the prompt said
- "Enter a number please. " my father typed "no". Of course it crashed and
- I had to learn another way to do things.
-
- Regards
- Chris Hall
-
- /--------------------------------------------------------------------------\
- | The world cannot end today because it is tomorrow in Australia... |
- | |
- | |________ Chris Hall |
- | ||OOO||________> hallch@handel.colostate.edu |
- | | |
- \__________________________________________________________________________/
-
-