home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / pascal / 7978 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  2.7 KB

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