Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Center text to a printer. 1

Status
Not open for further replies.

aviles22

Programmer
Jun 27, 2000
25
US
How can I center one line of text to a printer.<br><br>Is there a printer.center command
 
If the text is in out$ and the page is 80 colums, use the following:<br>PRINT SPACE$(40-LEN(OUT$)/2)&OUT$<br>I think you can also substitute (width/2) for 40<br>Dan
 
aviles22 -<br><br>You should know that Dan's suggestion only works under the following conditions:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;1) You're using a fixed-pitch font like Courier New or Roman<br>&nbsp;&nbsp;&nbsp;&nbsp;2) The length of text you're attempting to print doesn't exceed the number of available columns.&nbsp;&nbsp;<br><br>You should do something like this to prevent out of range errors:<br><br><FONT FACE=monospace><b>Private Sub CenterText(szText as String)<br>Const Width = 80<br>Dim szTemp as String<br>Dim iNumSpaces as Integer<br><br>&nbsp;&nbsp;&nbsp;&nbsp;szTemp = Left$(szText, Width)<br>&nbsp;&nbsp;&nbsp;&nbsp;iNumSpaces = (Width - Len(szTemp)) \ 2<br>&nbsp;&nbsp;&nbsp;&nbsp;Print Space$(iNumSpaces) & szTemp<br><br>End Sub</b></font><br><br>Note that this code truncates the supplied string so that it's guaranteed to fit.&nbsp;&nbsp;It also uses an integer division to always round down to the next integer when it calculates the number of spaces to insert.<br><br>Hope this helps.<br><br>Chip H.<br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top