home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.pascal
- Path: sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
- From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
- Subject: Re: want to help me make my 'value' routine crash-proof?
- Message-ID: <dmurdoch.66.714772006@mast.queensu.ca>
- Lines: 35
- Sender: news@knot.ccs.queensu.ca (Netnews control)
- Organization: Queen's University
- References: <1992Aug25.150516.17385@javelin.sim.es.com> <dmurdoch.65.714760154@mast.queensu.ca> <1992Aug25.191036.21639@javelin.sim.es.com>
- Date: Tue, 25 Aug 1992 19:46:46 GMT
-
- In article <1992Aug25.191036.21639@javelin.sim.es.com> tpehrson@javelin.sim.es.com ([SNES ClRv]) writes:
- >
- >>You haven't told us what you'd like this routine to do in that case. What
- >>is the 16 bit value of 99999? The question doesn't make sense.
- >
- >let me repeat:
- >>>maxing out at 65535 is desired.
- >
- >i want my routine to accept any 'number', in string form, such as
- >'99999999999999999999123459' and 1. not crash 2. return the maximum, 65535.
-
- You still haven't fully defined what you want, for example what to do if the
- string is '3.456' or 'Not a number' or 'seven'. If you want any error to
- return the maximum, just call val and check the error value, e.g.
-
- function value(s:string):word;
- var
- v : word;
- error : integer;
- begin
- val(s,v,error);
- if error <> 0 then
- value := 65535
- else
- value := v;
- end;
-
- As I mentioned, this isn't very satisfactory, since you can't tell 65535
- from an error, and you can't do things like:
-
- total := value(string1) + value(string2);
-
- without risking complete nonsense.
-
- Duncan Murdoch
-