home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / pascal / 5046 < prev    next >
Encoding:
Text File  |  1992-08-25  |  1.6 KB  |  47 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: want to help me make my 'value' routine crash-proof?
  5. Message-ID: <dmurdoch.66.714772006@mast.queensu.ca>
  6. Lines: 35
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <1992Aug25.150516.17385@javelin.sim.es.com> <dmurdoch.65.714760154@mast.queensu.ca> <1992Aug25.191036.21639@javelin.sim.es.com>
  10. Date: Tue, 25 Aug 1992 19:46:46 GMT
  11.  
  12. In article <1992Aug25.191036.21639@javelin.sim.es.com> tpehrson@javelin.sim.es.com ([SNES ClRv]) writes:
  13. >
  14. >>You haven't told us what you'd like this routine to do in that case.  What 
  15. >>is the 16 bit value of 99999?  The question doesn't make sense.  
  16. >
  17. >let me repeat:
  18. >>>maxing out at 65535 is desired.
  19. >
  20. >i want my routine to accept any 'number', in string form, such as 
  21. >'99999999999999999999123459' and 1. not crash 2. return the maximum, 65535.
  22.  
  23. You still haven't fully defined what you want, for example what to do if the 
  24. string is '3.456' or 'Not a number' or 'seven'.  If you want any error to 
  25. return the maximum, just call val and check the error value, e.g.
  26.  
  27. function value(s:string):word;
  28. var
  29.   v : word;
  30.   error : integer;
  31. begin
  32.   val(s,v,error);
  33.   if error <> 0 then
  34.     value := 65535
  35.   else
  36.     value := v;
  37. end;
  38.  
  39. As I mentioned, this isn't very satisfactory, since you can't tell 65535 
  40. from an error, and you can't do things like:
  41.  
  42.   total := value(string1) + value(string2);
  43.  
  44. without risking complete nonsense.
  45.  
  46. Duncan Murdoch
  47.