Output integers in graphics mode

How do you output integer values on-screen while in graphics mode as output and outputXY do not work!!!
oddishwannabeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
HypoConnect With a Mentor Commented:
First I guess that "Output" and "OutputXY" should be "OutText" and "OutTextXY".

You can convert integers to strings using the str function and then put them on the screen using the "OutText" or "OutTextXY" procedures.

That's one sollution!

Or you can make a function called IntToStr, wich takes one parameter (an integer value) and returns a string.

Like this,

Function IntToStr(X: integer) : string;
var S : string;
begin
 Str(X,S);
 IntToStr := S;
end;

The only reason for making the IntToStr function is that it's easier to use than the Str function.

for instance,
It's easier to code

Example1:
OutText('Xpos : '+ IntToStr(Xpos)+ ' Ypos : '+ IntToStr(Ypos));

than it is to use

Example2:
Str(Xpos,S);
Str(Ypos,T);
OutText('Xpos : '+ S +'  Ypos : '+ T);
 
Reason?
In Example1, you don't have to store the result of the str operation in a string since IntToStr returns a string itself, wich you have to do in Example2 (see T and S).

Ok, So IntToStr only makes it easier to use the Str function.

That's another sollution!

But! there is still another way to solve this problem of yours. You can use Write and WriteLn. Even if it's in graphic mode! Care to know how???

There's a variable in pascal called DirectVideo. When this variable is set to FALSE, write and writeln will draw to the screen even if you're in a graphical mode.

So instead of using "OutText" and
"OutTextXY" and convert values to strings etc. etc...

You can do like this...
Example3:

DirectVideo := False;
GotoXy(1,1);
Writeln('Xpos : ',Xpos,' Ypos : ',Ypos);
....
DirectVideo := True;
When you're done... Set DirectVideo to True!

So... You don't have to use "OutText" or "OutTextXY" to put text on the screen in a graphics mode. If you set DirectVideo to false you can also use "Write" and "Writeln"... wich are so much easier to use than "OutText" and "OutTextXY".

Regards Hypo.
0
 
dbruntonCommented:
Change them to a string.

In Turbo Pascal this is the Str procedure.  


Str(I, S) where I is integer to convert and S is string to place number.

Are you using Turbo because I don't recognise the out procedure?
0
 
oddishwannabeAuthor Commented:
Adjusted points to 75
0
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
oddishwannabeAuthor Commented:
Hypno, you're a god amongst men. Thank you!!
0
 
sumant032199Commented:
program outtext_integer;
uses Crt, Graph;

type str = array[1..7] of char;
var Gd, Gm,p: Integer;
    o : str;

procedure outtext_int(x : integer; var out : str);
var no_of_digits,i : integer;
    isnegative : boolean;
begin
    if x < 0 then isnegative := true
             else isnegative := false;
    x := abs(x);

    if x >= 10000 then  no_of_digits := 5 + ord(isnegative)
    else if x >= 1000 then no_of_digits := 4 + ord(isnegative)
    else if x >= 100 then no_of_digits := 3 + ord(isnegative)
    else if x >= 10 then no_of_digits := 2 + ord(isnegative)
    else no_of_digits := 1 + ord(isnegative);

    if isnegative then   out[1] := '-';

    i := no_of_digits;
    while x <> 0 do
    begin
         out[i] := chr(48+(x mod 10));
         x := x div 10;
         i := i - 1;
    end;
end;
begin
       Gd := Detect;
       InitGraph(Gd, Gm, '\tp\bgi');
       if GraphResult <> grOk then   Halt(1);
       outtext('Enter number: ');
       gotoxy(1,2);
       readln(p);
       outtext_int(p,o);

       writeln(o);
       outtext(o);

       readln;
       CloseGraph;
end.


0
 
amgedeldirdiriCommented:
You Can Use The Str Procedure To Change The Integer Value To String That OutTextXY Work With String But If You Your Value To OutPut You Can't Use The '' To Your New String ,You Can Use This Code
Var
  St:String;
  Value,Gd,Gm:Integer;
Begin
   Gd:=Detect;{Get Graph Driver}
   St:='';{To Make Your String Empty}
   InitGraph(Gd,Gm,'');{Init Your  Graphics Mode}
   Value:=10;{for Example}
   Str(Value,St);
   OutTextXY(100,50,St);{You Can See We Dont Have The '' With St Like This 'St' To Out Put The Value Of St Not St As Text}
End.
0
 
amgedeldirdiriCommented:
You Can Use The Str Procedure To Change The Integer Value To String That OutTextXY Work With String But If You Your Value To OutPut You Can't Use The '' To Your New String ,You Can Use This Code
Var
  St:String;
  Value,Gd,Gm:Integer;
Begin
   Gd:=Detect;{Get Graph Driver}
   St:='';{To Make Your String Empty}
   InitGraph(Gd,Gm,'');{Init Your  Graphics Mode}
   Value:=10;{for Example}
   Str(Value,St);
   OutTextXY(100,50,St);{You Can See We Dont Have The '' With St Like This 'St' To Out Put The Value Of St Not St As Text}
End.
0
All Courses

From novice to tech pro — start learning today.