473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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
Apr 21 '07 #1
4 4418
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

"Pascal" <sc*********@wanadoo.rfwrote in message
news:46***********************@news.orange.fr...
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

Apr 21 '07 #2
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
Apr 21 '07 #3
Pascal wrote:
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
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)

--
Göran Andersson
_____
http://www.guffa.com
Apr 21 '07 #4
Oh yes you are right
thank you
Apr 23 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john sutor | last post by:
Is there something wrogn with this syntax? It does not put in the padded characters. string hk="Assembly"; hk.PadRight(35,'-'); this.textBox1.Text=hk + "Test"; The output is AssemblyTest
1
by: jimmy chao via .NET 247 | last post by:
Hi I am having problems with using the padright function in ASP.NET. my code is string listring; string strTitle = ds.Tables.Rows.ToString().Trim(); if (strTitle.Length > 15) { strTitle =...
4
by: Arif Çimen | last post by:
Hi to everybody, I have chnged a button text in design mode. But After compiling and executing the program the text of the button do not change to new value. Any Ideas? Thaks for helps.
2
by: Reny | last post by:
Hi, I came across a doubt on the String.PadLeft Method.The doubt is this -- What's difference it make if the argument to this function carries an integer whose value is less than the length of...
2
by: Bill Nguyen | last post by:
I tried in vain to add blank space to the end of couple variables as below: mPadding = Convert.ToChar(" ") mdriverBegin.PadRight(16, mPadding) mdriverEnd.PadRight(16, mPadding) ...
3
by: MikeJ | last post by:
""NAME","SYSTEM_ID","TAX_ID","LICENSE""; the Above is one row read in from a text file its 38 bytes in width i want to pad this to 77 in my code padright is not working correctly unless i...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
2
by: akshaycjoshi | last post by:
Refer the pic below, It's showing properly when seen in notepad but not in combobox. Here is the code OleDbDataReader trunkdr = trunkcom.ExecuteReader(); while (trunkdr.Read()) {...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.