Link to home
Start Free TrialLog in
Avatar of swapnilv
swapnilv

asked on

Using Print #, Display line at center of user defined page width

Hi,

I am reading one text file which have fixed width(80). This files have few lines which I am reading e.g Line01 = "I am swapnil"
Now my software should read this file and using print # method it should print it into another text file whose width is defined by user. User may select above 80 any width. Say 100 then
Line01 should get printed into new text file at the center of page width(100)

Can somebody give me code for center align???

How to do that?

Regards
swapnil
Avatar of Dirk Haest
Dirk Haest
Flag of Belgium image

I guess you'll have to add spaces before you're string to center the text in your file...

dim CenterPos as integer
' centerpos =
' (linewidth / 2) -> give the middle of the line (center of page)
' line01 / 2 -> gives the middle of your string
CenterPos = (100 / 2) - round(len(line01) / 2,0)

Dim NewLine as string
for i = 1 to centerpos
   print " "
next i
print line01
Avatar of swapnilv
swapnilv

ASKER

Thanks man..

But the problem remains as it is.. I don't know how to proceed

the code is something like this..

Open TextFile For Output As #Numfile

Then I read line01

   Line01 = "I am swapnil"

    CenterPos = (100 / 2) - Round(Len(Line01) / 2, 0)

Dim NewLine As String
For Val1 = 1 To CenterPos
Print #Numfile, " "
Next
Print #Numfile, line01

It is printing with different lines in wordpad.whereas it should be in one line.

How to implement in one line.. I tried with spc(n) but I am not able to do with that also..I am not sure how to use spc().

Swapnil


dim CenterPos as integer
' centerpos =
' (linewidth / 2) -> give the middle of the line (center of page)
' line01 / 2 -> gives the middle of your string
CenterPos = (100 / 2) - round(len(line01) / 2,0)

Dim NewLine as string
for i = 1 to centerpos
   print " "
next i
print line01


ASKER CERTIFIED SOLUTION
Avatar of Xentor_
Xentor_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial