Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / April 2007

Tip: Looking for answers? Try searching our database.

how to use padright and padleft to aligne text in 2 columns ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Pascal - 21 Apr 2007 09:31 GMT
hello

i try to use padright and padleft to beautify the aspect of my prints. I 'd
like the text to be print in two columns but i don't know the size of each
string before (because they are randomly generated) I thought that padright
complete the lenght of a string to the size noticed as a variable like
padright (50)  if the string is 35 of lenght so padright add 15 to fit to
the given size of 50. But it seems it doesn't work like this ? Can some one
tell what doesn't work in this code ?
m_Paragraphs = New Collection

Dim mtEspaces As String = " = .......... "

For i As Integer = 1 To 20

Dim myStr1 As String = NbE(CShort(utility.GenNombre(Min, Max))) 'to build a
long number like  9 352

Dim myStr2 As String = NbE(CShort(utility.GenNombre(Min, Max))) 'to build a
long number like  9 352

m_Paragraphs.Add(New ParagraphInfo(11, i.ToString + ") ".PadRight(5) &
myStr1.PadRight(5) & mtEspaces.PadRight(50)  & myStr2.PadRight(5) &
mtEspaces))

m_Paragraphs.Add(New ParagraphInfo(9, vbCrLf))

Next

the string are not aligned in two columns....

thanks for help
pascal

http://www.scalpa.info
Rick - 21 Apr 2007 10:22 GMT
I didn't look at your code carefully, but you have to use a monospaced font
for your concept to work in general. Courier is an example.

Other fonts have varing character widths so a space is less width than a
"W".

You might also try to imbed a tab character (Chr(9)) and see if that works.

Rick

> hello
>
[quoted text clipped - 31 lines]
>
> http://www.scalpa.info
Pascal - 21 Apr 2007 11:53 GMT
thank you, you were right and also i have to calculate the longest string
before to apply a padright lenght according to this variable

thank again
pascal
Göran Andersson - 21 Apr 2007 21:42 GMT
> hello
>
[quoted text clipped - 31 lines]
>
> http://www.scalpa.info 

The expression i.ToString + ") ".PadRight(5) always creates the same
result, namely the same as i.ToString + ")    ". If you want to pad the
string including the number, you have to add parentheses so that the
entire string is padded, not just the second string:

(i.ToString + ") ").PadRight(5)

Signature

Göran Andersson
_____
http://www.guffa.com

Pascal - 23 Apr 2007 20:47 GMT
Oh yes you are right
thank you

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.