Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

writeln.....specifying spaces

83 views
Skip to first unread message

Alex E

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
I am writing to a printer port...

Any way that I can specify the column to start printing on....or setting
spaces...

writeln (f, 'mightymouse ','20 cards');

I get :
mightymouse 20 cards
mickeymouse 10 cards
etc.

I would like to at least align these columns, I would like to print straight
to the printer.

Thanks

Alex ..

David Knapp

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
You have checked that your printer is using a fixed (monospaced) space font,
right? Some default fonts give different amounts of space to the letters
'M' versus 'J', for example. Courier is usually monospaced.

Alex E

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
another example...with database fields ...lets say A and B

and I use

writeln (a,' ',b)

I wish to print Mickey mouse on the first column which it does,

and I would like to print 20 cards (cards column), to begin printing at
exactly 30 spaces from the left edge, so it stays aligned with the previous
fields...

* align at space 30
lets say
Mickey mouse 20 cards
Minnie mouse 10 cards

what happens is that the first fields could be any number of characters so I
can't just set spaces arbitrarily to separate the two fields....so i need to
set the column to start printing at to be 30...


Thanks alex..

David Knapp wrote in message <7q6i7p$rl...@forums.borland.com>...

Philippe Ranger

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
<<Alex:

writeln (f, 'mightymouse ','20 cards');

I get :
mightymouse 20 cards
mickeymouse 10 cards
etc.
>>

Yeah, but you don't say what code produces each line. If you use a
fixed-space (non-proportional) font, and in code you fill out your lines to
the same length, they'll print to the same length. If the font is
proportional, you just can't do it this way at all. In that case, you could
try and set tabs, the way the printer manual tells you (if it does), and use
tabs (^I) for alignment.

PhR


Rudy Velthuis

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
Alex E wrote:

>another example...with database fields ...lets say A and B
>
>and I use
>
>writeln (a,' ',b)
>
>I wish to print Mickey mouse on the first column which it does,

Old style:

Writeln(A:30, B:10, C:10:4);

will occupy 50 spaces (unless fields don't fit in), all right aligned (or
left for strings? see manual). C is a float value, 4 decimals.

This will print (without the ruler):
----+----1----+----2----+----3----+----4
Mickey Mouse 20
Minnie Mouse 7
Goofy 732

etc.
--
Have a nice Delphi day...
Rudy Velthuis

Philippe Ranger

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
<<Alex:

what happens is that the first fields could be any number of characters so I
can't just set spaces arbitrarily to separate the two fields....so i need to
set the column to start printing at to be 30...
>>

So, the question is how to pad out a string to a given length?

Function padOut(s: string; len: integer): string;
Begin
result := s;
if (length(s) >= len) then EXIT;
result := result + stringOfChar(' ', len - length(s));
End;

PhR


alex E

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
writeln(a:30,b:10);

works just fine.....now it prints my database fields in columns!!! great..

I don't have a manual, and all these newer books don't even touch these
basic commands......and for me, thats starting to learn, I can't even find
references on the web on some of these basic functions...

So if anyone knows how to left justify 'a' it is a string, the 'b' field is
an integer and it is right justified which is fine.....so what I get is this

Mickey Mouse 20
MinnieMouse 10
I want

Mickey Mouse 20
Minnie Mouse 10


thanks,

Alex

Rudy Velthuis <rvel...@gmx.de> wrote in message
news:MPG.12311e1e9...@forums.borland.com...

Philippe Ranger

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
<<Rudy:
Old style:

Writeln(A:30, B:10, C:10:4);
>>

This prints *right* aligned no matter what the type. It's not what Alex is
looking for. Help text --

----------
Write with one of the string-type values:

If MinWidth is omitted, the string value of OutExpr is written to the file
with no leading blanks. If MinWidth is specified, and its value is larger
than the length of OutExpr, enough blanks are written before the decimal
string to make the field width MinWidth.
--------------

It's always been a failing of Write that it doesn't provide for
right-padding.

PhR


Philippe Ranger

unread,
Aug 27, 1999, 3:00:00 AM8/27/99
to
<<Alex:

I don't have a manual, and all these newer books don't even touch these
basic commands
>>

They're completely covered in the Help -- use it assiduously.

<<
So if anyone knows how to left justify 'a' it is a string,
>>

I gave you a function for that.

PhR

alex E

unread,
Aug 28, 1999, 3:00:00 AM8/28/99
to
I will try that...PhR


Thanks,

Alex

Philippe Ranger <.> wrote in message news:7q7qcu$sh...@forums.borland.com...

Rudy Velthuis

unread,
Aug 28, 1999, 3:00:00 AM8/28/99
to
alex E wrote:

>writeln(a:30,b:10);
>
>works just fine.....now it prints my database fields in columns!!! great..
>

>I don't have a manual, and all these newer books don't even touch these

>basic commands......and for me, thats starting to learn, I can't even find
>references on the web on some of these basic functions...

You do have a manual (although not on paper). It's all in the help
files, in this case topic "Write procedure (for text files)".

Of course you could use Format in SysUtils instead (the string is left
aligned here):

Writeln(Format('%-30s%10d', [A, B]));

In the old days I'd do this:

L := 30 - Length(A);
Writeln(A, '':L, B:10);

This writes A left aligned, then an empty string preceded by L spaces,
then the B integer as shown before. Of course this only worked for
strings, but that was ok for me, most of the time.

Rudy Velthuis

unread,
Aug 28, 1999, 3:00:00 AM8/28/99
to
alex E wrote:

>> Writeln(A:30, B:10, C:10:4);
>> >>
>>
>> This prints *right* aligned no matter what the type. It's not what Alex is
>> looking for. Help text --

>> It's always been a failing of Write that it doesn't provide for
>> right-padding.

See also my other reply to Alex:

Writeln(A, '':30 - Length(A), B:10);

Dr John Stockton

unread,
Aug 28, 1999, 3:00:00 AM8/28/99
to
JRS: In article <7q7qcu$sh...@forums.borland.com> of Fri, 27 Aug 1999
23:34:46 in news:borland.public.delphi.objectpascal, Philippe Ranger

<?.?@?.?> wrote:
>
>It's always been a failing of Write that it doesn't provide for
>right-padding.

True. But many do not realise that '':N can sometimes be used to get
the desired effect easily enough. Write(A, '':30-Length(A), B) ;

--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c. FAQqish topics, links.
Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
<A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.

Rudy Velthuis

unread,
Aug 28, 1999, 3:00:00 AM8/28/99
to
Dr John Stockton wrote:

>True. But many do not realise that '':N can sometimes be used to get
>the desired effect easily enough. Write(A, '':30-Length(A), B) ;

Hehe. I used to do the same (see my other reply a few hours ago). It
only worked for strings of course.


alex E

unread,
Aug 29, 1999, 3:00:00 AM8/29/99
to
Thanks Rudy, Dr.Stockton, and PhR...
I am starting to see the hidden attributes of writeln.....or ways to get
around its limitations....

on the same topic......of writeln........

I have tried this...on parallel port printers

Assignfile(F,'LPT1')
rewrite (F);
Writeln(F,'Hello there');
closefile(f);

...works

So I tried writing to a printer that has a comm port...
Assignfile(F,'com1')
rewrite (F);
Writeln(F,'Hello there');
closefile(f);

Strangely enough.....the printer does something...goes through ....making
like it prints, I could have 20 writeln lines, and it spits out 20
lines.........but no characters...how do you send characters to a printer on
a serial port... can writeln...be made to do this....?

I think this might be harder than writing to parallel port.... but more than
likely there is an easy way to do this....(but in my weeks of experience,
its just not coming to me.....)

....I find difficult to sort through delphi's online help......I find it a
little confusing.....I think the problem is I
understand some .....but 'obviously'....not all of pascal............

ANyways.... I am beginning to ramble on....any ideas on this comm port
printing issue.....


THanks..

Alex...

P.S. last thought....would you need a third party component for this???

P,S,S. As a beginner....I am sorry if these questions seem a little off the
wall....I am just learning each command one by one....and I find it
helpfull. to try and do every possible example that comes to mind... with
each command.....and frankly I think I have exausted WRITELN.....


Rudy Velthuis <rvel...@gmx.net> wrote in message
news:37ce6a6f...@forums.borland.com...

0 new messages