Align the text 
Author Message
 Align the text

hey

How can I aligh a text to the right?

 I mean, if i have: writeln('xx..');
I want it to appear at the right of the screen.

and also, how to center it at the middle of the screen?

Thanks!

--
Posted via CNET Help.com
http://www.*-*-*.com/



Sat, 15 Mar 2003 03:00:00 GMT  
 Align the text
{Have fun with the code, DjAttitude}

uses crt;

Procedure WriteLnRight(S:String);
Var oy:integer;
 Begin
  oy:=wherey;
  Gotoxy(79-(Length(S)),oy);
  Writeln(s);
 End;

Procedure WriteLnCenter(S:String);
Var oy:integer;
 Begin
  oy:=wherey;
  Gotoxy(39-(Length(S) DIV 2),oy);
  Writeln(s);
 End;

begin
 WriteLnRight('Welcome to the world of fun');
end.



Sat, 15 Mar 2003 03:00:00 GMT  
 Align the text

Quote:
> {Have fun with the code, DjAttitude}

> uses crt;

> Procedure WriteLnRight(S:String);
> Var oy:integer;
>  Begin
>   oy:=wherey;
>   Gotoxy(79-(Length(S)),oy);
>   Writeln(s);
>  End;

> Procedure WriteLnCenter(S:String);
> Var oy:integer;
>  Begin
>   oy:=wherey;
>   Gotoxy(39-(Length(S) DIV 2),oy);
>   Writeln(s);
>  End;

> begin
>  WriteLnRight('Welcome to the world of fun');
> end.

My Pascal (FPC) has the left upper corner 1,1 in the text screen.
WriteLnRight:
If your screen size is height x 80 it must be 81-Lenght(S). Else use
41-Lenght(S) in case the width is 40. Usually it is 80.
WriteLnCenter:
41-(Lenght(S) div 2) works better. String should not be longer than 80 of
course. For screen width 40 use 21-(Lenght(S) div 2).
Don't forget div 2 is the same as shr 1 (which is faster)!
You can simply test it by putting a string of lenght 80 (or 40) on the
screen.

KuifWare,
kuifware.freeservers.com



Sun, 16 Mar 2003 03:00:00 GMT  
 Align the text



Quote:
>hey

>How can I aligh a text to the right?

> I mean, if i have: writeln('xx..');
>I want it to appear at the right of the screen.

>and also, how to center it at the middle of the screen?

This is the "misc" group, so we do not know which Pascal you use, nor
the nature of your screen.  If you are using TP, for example, ask in
c.l.p.borland.  Otherwise, specify.

You should not use GoToXY if it can comfortably be avoided; a program is
more portable if it only uses the essential features of the language.

Firstly, how big is the screen?  In DOS, you can find out by system
calls, or by reading addresses in $40:$00-$FF, or you can assume 80*25.
On this machine, and often on another, I use 80*50.

Assuming that your Pascal resembles TP :

Write('xx..':79) will cause it to appear almost at the right of a
screen; 80 might cause the line to wrap.

Write('xx..':42), by left-padding the string, will write in the centre
of the line.  Or S := 'xx..' ; Write(S: 40 + length(S) div 2).

For the centre of the screen, *if* you know that you are at the top, you
*can* write blank lines to get down to the middle :
        Write(^J^J^J^J^J^J^J^J^J^J^J^J'xx..':42)
but most would use GoToXY or equivalent.

--

 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.



Sun, 16 Mar 2003 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. align vertically

2. Align Stringgrid

3. Align String grids

4. TASM: "ALIGN"ing addresses w/ model TPASCAL

5. Aligned 32-bit move() and fillchar() replacement

6. ADDING TEXT TO A TEXT FILE

7. Saving Rich Text to sql server Text Fields

8. Scrolling Text in Text Mode - PLEASE HELP!

9. Convert UNIX text to DOS text

10. Unix Text File ---> DOS Text File

11. Search for text string in a text file

12. Search for text string in a text file

 

 
Powered by phpBB® Forum Software