Solved

Output integers in graphics mode

Posted on 2000-03-01
7
319 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 47

Expert Comment

by:dbrunton
Comment Utility
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
Comment Utility
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
Comment Utility
Adjusted points to 75
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

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

Expert Comment

by:sumant032199
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Marketing can be an uncomfortable undertaking, especially if your material is technology based. Luckily, we’ve compiled some simple and (relatively) painless tips to put an end to your trepidation and start your path to success.
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now