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> 1) You're using a fixed-pitch font like Courier New or Roman<br> 2) The length of text you're attempting to print doesn't exceed the number of available columns. <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> szTemp = Left$(szText, Width)<br> iNumSpaces = (Width - Len(szTemp)) \ 2<br> 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. 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>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.