home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol023 / strval.lib < prev    next >
Text File  |  1984-04-29  |  646b  |  31 lines

  1.  
  2. {string value routine}
  3.  
  4. FUNCTION stringval (VAR str : string255) : integer;
  5.  
  6. CONST    zero = 48;
  7.  
  8. VAR    value : real;
  9.     loc : integer;
  10.     negative : boolean;
  11.  
  12. begin
  13.     loc := 1;
  14.     negative := false;
  15.     value := 0.0;
  16.     for loc := 1 to length(str) do
  17.         if (str[loc] >= '0') and (str[loc] <= '9') then
  18.             value := (10.0 * value) + ord(str[loc]) - zero
  19.             else if (str[loc] = '-') then
  20.                 negative := true;
  21.     if (negative = true) then value := -value;
  22.     if (value < maxint) and (value > -maxint) then
  23.         stringval := trunc(value)
  24.     else
  25.         begin
  26.         writeln (' *** Value of string exceeds integer range ***');
  27.         stringval := 0
  28.         end
  29. end;
  30.  
  31.