By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,328 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

Help Please: Vb6.0 Aligning Columns of Numbers in a multiline textbox (Format Function)

P: n/a
I need to display several columns of numbers in a textbox. I wish to
display the columns with the decimal point position aligned vertically.

I have found that the # digit placeholders do not reserve the spaces for the
number if the number of digits are fewer than the number of placeholders.

My simplified example: included within a loop such that it displays two
columns
Text1.Text = Text1.Text & Format(x, " ###.#0") & _
Format(y, " #,###.0") & _
vbCrLf
The digit place holders do not hold the places when the number of digits in
the values of x and y are fewer than the number of place holders (#). This
causes the columns to not align.

I can make the columns align by placing a (0) placeholder at the most
significant digit to the left of the decimal but then the columns are
displayed with numbers of leading zeros depending on how many significant
digits are actually required to display the value in a particular row.

Example:

00000012.01 2345 0000000000.25

Help would be appreciated.
I recall that this was the only method to reserve spaces for the purposes of
alignment of columns in earlier forms of Basic and Fortran. It seems that
VB digit placeholders only reserve spaces for actual digits of the value to
be displayed.



Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Wed, 22 Jun 2005 21:36:30 -0700, "Rookie" <go***@adelphia.net>
wrote:
I need to display several columns of numbers in a textbox. I wish to
display the columns with the decimal point position aligned vertically.

I have found that the # digit placeholders do not reserve the spaces for the
number if the number of digits are fewer than the number of placeholders.


Why do you want to use a Textbox ?

Do you intend manually editing the numbers ?

If this is just for display, then print them directly on the face of a
Form, Picturebox or UserControl
Jul 17 '05 #2

P: n/a
Thanks for your Reply,

I used a text box so I could add a vertical scroll bar as there are up to
300 rows of data and because I am totally new to vb.

What I really want to know is if there is a way to fix the place holders to
main columnar alignment.

Gary

"J French" <er*****@nowhere.uk> wrote in message
news:42***************@news.btopenworld.com...
On Wed, 22 Jun 2005 21:36:30 -0700, "Rookie" <go***@adelphia.net>
wrote:
I need to display several columns of numbers in a textbox. I wish to
display the columns with the decimal point position aligned vertically.

I have found that the # digit placeholders do not reserve the spaces for
the
number if the number of digits are fewer than the number of placeholders.


Why do you want to use a Textbox ?

Do you intend manually editing the numbers ?

If this is just for display, then print them directly on the face of a
Form, Picturebox or UserControl


Jul 17 '05 #3

P: n/a
On Thu, 23 Jun 2005 18:18:52 -0700, "Rookie" <go***@adelphia.net>
wrote:
Thanks for your Reply,

I used a text box so I could add a vertical scroll bar as there are up to
300 rows of data and because I am totally new to vb.

What I really want to know is if there is a way to fix the place holders to
main columnar alignment.


You really need to use some sort of Grid or the Listview for this sort
of thing.

However, if you insist on using a Textbox, then you could use a fixed
font (ie: not a proportional font) typically Courier.
Jul 17 '05 #4

P: n/a
Use tabstops. See http://vbnet.mvps.org/code/textapi/txboxtabs.htm. No
padding with spaces required.

If you want a tool to help design the tabstop positions, including
right-justified tabstops for numbers, you can use
http://vbnet.mvps.org/code/listapi/cooltabs.htm (that utility uses a listbox
to set the alignment code, but the "Generate" code option allows you to
specify the tool should create code for a listbox or for a textbox). Right
click either the header or listbox for other options.

There is also the listview control that may be more suitable, which also
allows sorting of each column of numbers.

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------

"Rookie" <go***@adelphia.net> wrote in message
news:l4********************@adelphia.com...
:I need to display several columns of numbers in a textbox. I wish to
: display the columns with the decimal point position aligned vertically.
:
: I have found that the # digit placeholders do not reserve the spaces for
the
: number if the number of digits are fewer than the number of placeholders.
:
: My simplified example: included within a loop such that it displays two
: columns
:
:
: Text1.Text = Text1.Text & Format(x, " ###.#0") & _
: Format(y, " #,###.0") & _
: vbCrLf
:
:
: The digit place holders do not hold the places when the number of digits
in
: the values of x and y are fewer than the number of place holders (#).
This
: causes the columns to not align.
:
: I can make the columns align by placing a (0) placeholder at the most
: significant digit to the left of the decimal but then the columns are
: displayed with numbers of leading zeros depending on how many significant
: digits are actually required to display the value in a particular row.
:
: Example:
:
: 00000012.01 2345 0000000000.25
:
: Help would be appreciated.
:
:
: I recall that this was the only method to reserve spaces for the purposes
of
: alignment of columns in earlier forms of Basic and Fortran. It seems that
: VB digit placeholders only reserve spaces for actual digits of the value
to
: be displayed.
:
:
:
:
:
:
:
:
:

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.