printing variable problems

This is a discussion on printing variable problems within the Pascal forums in Programming Languages category; Hey all. I'm doing an ordering / booking system which is capable of printing invoices. The only thing which really annoys me at the moment is that if I want two variables printed (from printer to paper, not to screen) on the same line, then the length of the first variable affects the layout of the second variable. I'll give an example as I'm not so good at explaining. I want a part of my invoice to look like this when printed on paper: Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail Pipe Description: 18" Wheel Trim Description: 20" ...

Go Back   Application Development Forum > Programming Languages > Pascal

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 04-11-2006, 05:01 PM
jaf.2k@ntlworld.com
Guest
 
Default printing variable problems

Hey all.

I'm doing an ordering / booking system which is capable of printing
invoices. The only thing which really annoys me at the moment is that
if I want two variables printed (from printer to paper, not to screen)
on the same line, then the length of the first variable affects the
layout of the second variable. I'll give an example as I'm not so good
at explaining.

I want a part of my invoice to look like this when printed on paper:

Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail Pipe

Description: 18" Wheel Trim Description: 20" Wheel Trim


It will not look like that, instead it will look like this:


Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail Pipe

Description: 18" Wheel Trim Description: 20" Wheel Trim


The length of my 'stock name' variable affects the layout of things
horizontal from it when printed. In the above '18" Wheel Trim' is
shorter than '4" Exhaust Tail Pipe' and so the text and variable are
brought further left automatically. This can start to get messy when
lots of items are printed. GotoXY only works for printing variables to
screen, and I've tried printing spaces but that would only help for the
current stock item, there are loads of stock items so this doesn't
work. Any help would be greatly appreciated.

Cheers.

Reply With Quote
  #2  
Old 04-11-2006, 07:15 PM
Robert AH Prins
Guest
 
Default Re: printing variable problems

<jaf.2k@ntlworld.com> wrote in message
news:1144789243.835930.249590@i39g2000cwa.googlegr oups.com...
> Hey all.
>
> I'm doing an ordering / booking system which is capable of printing
> invoices. The only thing which really annoys me at the moment is that
> if I want two variables printed (from printer to paper, not to screen)
> on the same line, then the length of the first variable affects the
> layout of the second variable. I'll give an example as I'm not so good
> at explaining.
>
> I want a part of my invoice to look like this when printed on paper:
>
> Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail
> Pipe
>
> Description: 18" Wheel Trim Description: 20" Wheel Trim
>
> It will not look like that, instead it will look like this:
>
> Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail
> Pipe
>
> Description: 18" Wheel Trim Description: 20" Wheel Trim
>
> The length of my 'stock name' variable affects the layout of things
> horizontal from it when printed. In the above '18" Wheel Trim' is
> shorter than '4" Exhaust Tail Pipe' and so the text and variable are
> brought further left automatically. This can start to get messy when
> lots of items are printed. GotoXY only works for printing variables to
> screen, and I've tried printing spaces but that would only help for
> the
> current stock item, there are loads of stock items so this doesn't
> work. Any help would be greatly appreciated.


Create a string[n] variabe and assing the concatenation of your
'Description:' + the actual description + a load of spaces to it.
Pascal's strictly enforced type-checking will discard the spaces that
exceed the declared length of the string.

HTH,

Robert
--
Robert AH Prins
prino at prino dot plus dot com


Reply With Quote
  #3  
Old 04-11-2006, 08:58 PM
JG
Guest
 
Default Re: printing variable problems


jaf.2k@ntlworld.comsaid

> I'm doing an ordering / booking system which is capable of printing
> invoices. The only thing which really annoys me at the moment is that
> if I want two variables printed (from printer to paper, not to screen)
> on the same line, then the length of the first variable affects the
> layout of the second variable. I'll give an example as I'm not so good
> at explaining.


> I want a part of my invoice to look like this when printed on paper:


> Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail Pipe


> Description: 18" Wheel Trim Description: 20" Wheel Trim



> It will not look like that, instead it will look like this:



> Description: 4" Exhaust Tail Pipe Description: 5" Exhaust Tail Pipe


> Description: 18" Wheel Trim Description: 20" Wheel Trim



> The length of my 'stock name' variable affects the layout of things
> horizontal from it when printed. In the above '18" Wheel Trim' is
> shorter than '4" Exhaust Tail Pipe' and so the text and variable are
> brought further left automatically. This can start to get messy when
> lots of items are printed. GotoXY only works for printing variables to
> screen, and I've tried printing spaces but that would only help for the
> current stock item, there are loads of stock items so this doesn't
> work. Any help would be greatly appreciated.


You will need to write a set of routines to control your printer
directly. I have done so for Epson's that use ESC P2 codes and there are
specific codes to position the print head at what are effectively
horizontal and vertical 'TAB' positions.

If you would like a .PDF file detailing the Epson codes then I could
attach it to an e-mail.

JG
Reply With Quote
  #4  
Old 04-12-2006, 03:40 AM
Klaus Jorgensen
Guest
 
Default Re: printing variable problems

jaf.2k@ntlworld.com wrote :
>
> I'm doing an ordering / booking system which is capable of printing
> invoices. The only thing which really annoys me at the moment is that
> if I want two variables printed (from printer to paper, not to screen)
> on the same line, then the length of the first variable affects the
> layout of the second variable.


If you want to control your printer without using escape sequences, you
could write a function to return a given number of spaces - e.g.
space(30).

Then write your strings as:
writeln('Description: ',var1,^M,space(30),'Description: ',var2);


/klaus


Reply With Quote
  #5  
Old 04-12-2006, 03:54 AM
Marco van de Voort
Guest
 
Default Re: printing variable problems

On 2006-04-12, Klaus Jorgensen <kj@no.spam> wrote:
>> on the same line, then the length of the first variable affects the
>> layout of the second variable.

>
> If you want to control your printer without using escape sequences, you
> could write a function to return a given number of spaces - e.g.
> space(30).


If it is a printer that uses a proportional font that won't work. Escape
sequences, and hoping that you have a printer that is still doscompatible.

To circumvent these kind of problems myself, I wrote TeX code once, and
compiled it to PS or PDF that I then could throw binary to the printer.
Reply With Quote
  #6  
Old 04-12-2006, 09:11 AM
Dr John Stockton
Guest
 
Default Re: printing variable problems

JRS: In article <4a2o2eFr6ldeU1@individual.net>, dated Tue, 11 Apr 2006
23:14:45 remote, seen in news:comp.lang.pascal.borland, Robert AH Prins
<prino@onetel.com> posted :
>
>Create a string[n] variabe and assing the concatenation of your
>'Description:' + the actual description + a load of spaces to it.
>Pascal's strictly enforced type-checking will discard the spaces that
>exceed the declared length of the string.


I'd prefer to write a function that, given a string, returns that string
with trailing spaces added to bring it to stated length; or that writes
as if given such a string.

const Plenty = ' ' ;

function SL(const S : string ; const L : byte) : string ;
begin SL := S + copy(Plenty, 1, L-length(S)) end {SL} ;


function WS(const S : string ; const L : byte) : string ;
begin Write(S, '':L-length(S)) end {WS} ;


Untested : but something similar should work.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Reply With Quote
  #7  
Old 04-12-2006, 10:11 AM
dik
Guest
 
Default Re: printing variable problems


with:

procedure sl (s : string ; l : integer) ;
begin
if length (s) < l then
fillchar (s [length (s) + 1], l - length (s), ' ') ;
s [0] := char (l) ; sl := s ;
end ;

format output:

writeln (invoice, 'Description: ', sl (item_name, 33) ... etc) ;

DIK

Reply With Quote
  #8  
Old 04-12-2006, 10:31 AM
dik
Guest
 
Default Re: printing variable problems

sorry ... function sl not procedure sl - DIK

Reply With Quote
  #9  
Old 04-12-2006, 12:46 PM
JG
Guest
 
Default Re: printing variable problems


"dik" <quagga5@yahoo.com>said

> with:


> procedure sl (s : string ; l : integer) ;
> begin
> if length (s) < l then
> fillchar (s [length (s) + 1], l - length (s), ' ') ;
> s [0] := char (l) ; sl := s ;
> end ;


> format output:


> writeln (invoice, 'Description: ', sl (item_name, 33) ... etc) ;


Wont work when proportional spaced font is used (the most common scenario).

JG
Reply With Quote
  #10  
Old 04-12-2006, 02:15 PM
Klaus Jorgensen
Guest
 
Default Re: printing variable problems

Marco van de Voort wrote :
> On 2006-04-12, Klaus Jorgensen <kj@no.spam> wrote:
>>> on the same line, then the length of the first variable affects the
>>> layout of the second variable.

>>
>> If you want to control your printer without using escape sequences, you
>> could write a function to return a given number of spaces - e.g.
>> space(30).

>
> If it is a printer that uses a proportional font that won't work.



I'm no expert in proportional fonts, but are you telling me that
printing a string that is prefixed with a given number of space
characters, does not always start at the same position?

Will the printer print the xxx's on a different position if printed as
follows:
writeln(space(30),'xxx iiiiiiii');
writeln(space(30),'xxx mmmmmmmm');

Just curious - IIRC, I used proportional fonts on a laser-printer many
years back without any problems.


/klaus


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:43 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.