STR procedure and runtime error 215 
Author Message
 STR procedure and runtime error 215

I'm trying to convert a longint to a string. it worked but then the
numbers didn't show up right so I enabled overflow checking and range
checking. Now I get runtime error 215. is this a bug in BP/TP 7.0?
I can't change the variable to a word because it has to do with filesizes.
Anybody have a routine to convert numbers to strings?



Wed, 18 Jun 1902 08:00:00 GMT  
 STR procedure and runtime error 215

I don't have a routine written but here's how I'd do it:

Function MakeLongintString(x:longint): string;
var x: longint;
    i: integer;
    s: string;

begin
  s := '';
  repeat  
    s := chr (x mod 10 + Ord('0')) + s;
    x := x div 10
  until x = 0;
  MakeLongintString := s
end;

You can replace the Ord ('0') with 48, but its actually a little clearer with
the reference to zero there.  Essentially what I'm doing is finding the
character as an offset from the zero character.  

I don't know if the loop structure is correct, you might want to try a while
loop, and a make sure the ending condition is right.

Ken


says...

Quote:

>I'm trying to convert a longint to a string. it worked but then the
>numbers didn't show up right so I enabled overflow checking and range
>checking. Now I get runtime error 215. is this a bug in BP/TP 7.0?
>I can't change the variable to a word because it has to do with filesizes.
>Anybody have a routine to convert numbers to strings?

--
Views expressed herein are not necessarily the views
of Ontrack Computer Systems, Inc. or Ontrack Data Recovery, Inc.
*******************************************************************
* Ken Stieers               |  Minneapolis - 1.800.872.2599       *
* AV Research/Apps. Eng.    |  Los Angeles - 1.800.752.7557       *
* Ontrack Computer Systems  |  Washington, D.C. - 1.800.650.2410  *
* Ontrack Data Recovery     |  London - 0800 24 39 96             *
* Eden Prairie, MN          |  Japan - 81.429.32-6365             *
*******************************************************************


Wed, 18 Jun 1902 08:00:00 GMT  
 STR procedure and runtime error 215

Str (procedure)

Converts a numeric value to a string.

Declaration

procedure Str(X [: Width [: Decimals ]]; var
S:string);

Target

Windows, Real, Protected

Remarks

Converts the numeric value X to the same string representation that would
be output by Write.

See Also

Val
Write (text)
Write (typed)

Sample Code

{Str.PAS}

{Sample code for the Str procedure.}

{ For Windows: }
{ uses WinCrt; }

function IntToStr(I: Longint): String;
{ Convert any integer type to a string }
var
  S: string[11];
begin
  Str(I, S);
  IntToStr := S;
end;
begin
  Writeln(IntToStr(-5322));
  Readln;
end.



Wed, 18 Jun 1902 08:00:00 GMT  
 STR procedure and runtime error 215

Quote:
> I'm trying to convert a longint to a string. it worked but then the
> numbers didn't show up right so I enabled overflow checking and range
> checking. Now I get runtime error 215. is this a bug in BP/TP 7.0?
> I can't change the variable to a word because it has to do with filesizes.
> Anybody have a routine to convert numbers to strings?

   Str will do it; don't use the Overflow checking and be sure to cast
your integer/Word variables before using them in LongInt computation(s).


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. runtime error 215

2. FPC: runtime error 215 - lack in documentation....

3. RunTime error 215?

4. runtime error 215

5. Runtime Error 215 : What is it?

6. What is DOS ERROR 215

7. What is ERROR 215

8. Runtime errors and exit procedures

9. Error #215 Arithmetic overflow, where it shouldn′t occur(?)

10. Heap Overflow Error - runtime error 203

11. How to add stored procedure at runtime?

12. Confusing runtime error porting to TPW

 

 
Powered by phpBB® Forum Software