Solved

Output integers in graphics mode

Posted on 2000-03-01
7
332 Views
Last Modified: 2010-04-16
How do you output integer values on-screen while in graphics mode as output and outputXY do not work!!!
0
Comment
Question by:oddishwannabe
7 Comments
 
LVL 48

Expert Comment

by:dbrunton
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

by:
Hypo earned 75 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

by:oddishwannabe
ID: 2575812
Adjusted points to 75
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

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

Expert Comment

by:sumant032199
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);
       readln(p);
       outtext_int(p,o);

       writeln(o);
       outtext(o);

       readln;
       CloseGraph;
end.


0
 

Expert Comment

by:amgedeldirdiri
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}
   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
 

Expert Comment

by:amgedeldirdiri
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}
   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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
For months I had no idea how to 'discover' the IP address of the other end of a link (without asking someone who knows), and it drove me batty. Think about it. You can't use Cisco Discovery Protocol (CDP) because it's not implemented on the ASAs.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question