Solved

# Output integers in graphics mode

Posted on 2000-03-01
Medium Priority
353 Views
How do you output integer values on-screen while in graphics mode as output and outputXY do not work!!!
0
Question by:oddishwannabe
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 49

Expert Comment

ID: 2575394
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

LVL 12

Accepted Solution

Hypo earned 300 total points
ID: 2575764
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

Author Comment

ID: 2575812
0

Author Comment

ID: 2575813
Hypno, you're a god amongst men. Thank you!!
0

LVL 3

Expert Comment

ID: 2577638
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);
outtext_int(p,o);

writeln(o);
outtext(o);

CloseGraph;
end.

0

Expert Comment

ID: 2611039
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}
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

Expert Comment

ID: 2611041
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}
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read on to get a few ideas on how to promote your next corporate event.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
###### Suggested Courses
Course of the Month10 days, 9 hours left to enroll