Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying Variable's In GRAPH & variable conversion

Status
Not open for further replies.

TheElusiveYak

Programmer
Feb 8, 2004
19
US
Hello Again.
I am trying to write my first graphical program and I
tryed to display a variable of integer type using
outtext but I get a wrong variable type error.
Is there a procedure that displays the value of Variables?

Also
I am having difficulty writing a procedure that convertsa numerical string into an Integer. If you can, please help me with this. Thanx
 
Use the IntToStr Function

eg

TextOut(x,y,IntToStr(IntVaue));

John Pears, Coventry, England.
 
Well, It's a long time from my turbo days. I now use Delphi for everything ( inc. "DOS" or console apps. )
In Delphi, IntToStr is in the SysUtils unit.
But in case that's no good for you, and you can't find it, this will do the trick.


Code:
{-------------------------------------------------------}
function IntToStr(aValue:integer):string;
const
  Ch:array[0..9] of char =
      ( '0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' );
var
  I:integer;
  S:string;
begin
  S := '';
  I := abs(aValue);
  While I > 0 do
  begin
    S := Ch[ I mod 10 ] + S;
    I := I div 10;
  end;
  if aValue < 0 then
     S := '-' + S;
  IntToStr := S;
end;

{-------------------------------------------------------}
OR
Code:
{-------------------------------------------------------}
function IntToStr2(aValue:integer):string;
var
  I:integer;
  S:string;
begin
  S := '';
  I := abs(aValue);
  While I > 0 do
  begin
    S := Chr( ord('0') + ( I mod 10 ) ) + S;
    I := I div 10;
  end;
  if aValue < 0 then
     S := '-' + S;
  IntToStr2 := S;
end;

{-------------------------------------------------------}

John Pears, Coventry, England.
 
ERROR *** ERROR

Both of the last two functions could return an empty string if you where to try
Code:
 foo := IntToStr(0);
[\code]
so change to
[code]
function IntToStr2(aValue:integer):string;
var
  I:integer;
  S:string;
begin
  if aValue = 0 then
    IntToStr := '0'
  else
  begin
    S := '';
    I := abs(aValue);
    While I > 0 do
    begin
      S := Chr( ord('0') + ( I mod 10 ) ) + S;
      I := I div 10;
    end;
    if aValue < 0 then
       S := '-' + S;
    IntToStr2 := S;
  end;
end;


John Pears, Coventry, England.
 
OK there are typo's again, but you know what I mean.

John Pears, Coventry, England.
 
Fact is you don't need to include a library for that in Turbo pascal.

Simply declare a text variable to hold the result and use 'str' procedure.

var temp: string;

str(number, temp);

Do this conversion from number to text first, then use the 'temp' variable inside the graphic procedure (don't use str-procedure inside graphic output).

If you are working on real variables, you can format the output like:

str(murealnum:1:0,temp);{whole number and roundup}
str(murealnum:1:1,temp);{one decimal}
str(murealnum:1:2,temp);{two decimal and so on}

 
Converting a numerical string into an Integer
does not require a library either, but the procedure needs an extra numeric variable (temp=numeric string, mynumeric= integer, real etc):

var code: integer;

val(temp,mynumeric,code);

If 'code' contains zero, the conversion was successful, else error in the string.

 
Well thanx guys. Now everything is working great. You were a real help.
 
Compiler for use under Windows XP?

Can anyone suggest a compiler which I can use to write
programs for use under Windows XP?

My primary computer runs MSDOS 6.22 and it's great for
number crunching, elementary word processing and so forth.
I've written a number of useful utilities for it, such as
an almanac giving sunrise, sunset and moon phase for today,
a calendar which displays a calendar for any year after
1583, two directory programs, a word processor similar to
DEC's Runoff program, a file compare program, a program to
look at a text file (but not alter it), a dump program, a
string sort program, programs to "clean up" Pascal and C
programs, simple graphing programs and so on. Most of
these routines were written in Turbo Pascal, with a few in
assembly language.

Although C and C++ are very popular programming languages,
I far prefer to program in Pascal; I like the fact that
Pascal forces you to define every variable and procedure
before they are referenced -- not because I like
discipline, but because it helps prevent obscure bugs, such
as invoking a procedure with a REAL argument when the
procedure expects an INTEGER argument. I also like the
basic simplicity of the Pascal language. If no Pascal
compiler is available, I would reluctantly use a C or C++
compiler. Of course, the compiler must generate executable
code (i.e. an EXE file) and it should support elementary
graphing (e.g. Daily temperature vs. month). I won't
consider any form of BASIC.

Note that I would prefer to buy a commercial compiler,
rather than a free one. I need the written documentation.

Your assistance and comments would be greatly appreciated.

Harry.
 
Harry,

I agree that stepping into C/C++ (and many other languages) IS a big step. I've been programming in pascal since '87 but don't use it much any more. Now I'm more focused on PHP -but that's another story. AND there are indeed preferences to pascal. BUT you get used it other languages once you set your mind to it. Perhaps you should consider Delphi .... !?

However, I would suggest that you have a look at freePascal:


You'll love the IDE which is very similar to what you get with TP/BP.

Good Luck


Jakob
 
Delphi is what you want, likely. Freepascal can work for simple conversions of your programs - going from TP/BP to Delphi takes conversions of your old programs (which I'm somewhat in the process of doing with some of the more interesting ones - not easy for sure, it's almost like rewriting them - and that's just to work in Win32 command-line mode, not to mention if you want a form or three.)

Even though, your old programs can still be made to work well in Windows XP and fast machines through various and numerous methods.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top