473,396 Members | 1,712 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,396 software developers and data experts.

Formating in listbox

Hi
I am trying to add two variables to a list box and keep everything in line.I
get the result below

Gaz £2000
Jimmy £3000
fred £4000

but would like to get this result
Gaz £2000
Jimmy £3000
fred £4000

I am using to courier font so the letter are equally spaced but don't know
how to format the spaces to take into account the different length of the
variables

Any pointers
--
cheers dude
************
kin®sole
************


Jul 17 '05 #1
6 4150
Start with a fixed string length....

Next, subtract the length of the name, and the length of
the pound amount, and this leaves you with the number
of spaces to put in between, to format them properly.

number_of_spaces = max_string_length - name_length - pound_length

formatted_string$ = name$ + string$(number_of_spaces, " ") + pound$

As a sidenote, for better format alignment, I would
suggest switching to the "fixedsys" font, if all the
characters you need are available in it.
--
C.L. Mayeux
Owner, MSB Data Systems

"Kin®sole" <ki******@NOSPAMhotmail.com> wrote in message
news:23******************************@news.teranew s.com...
Hi
I am trying to add two variables to a list box and keep everything in line.I get the result below

Gaz £2000
Jimmy £3000
fred £4000

but would like to get this result
Gaz £2000
Jimmy £3000
fred £4000

I am using to courier font so the letter are equally spaced but don't know
how to format the spaces to take into account the different length of the
variables

Any pointers
--
cheers dude
************
kin®sole
************

Jul 17 '05 #2

"Kin®sole" <ki******@NOSPAMhotmail.com> wrote in message
news:23******************************@news.teranew s.com...
Hi
I am trying to add two variables to a list box and keep everything in line.I get the result below

Gaz £2000
Jimmy £3000
fred £4000

but would like to get this result
Gaz £2000
Jimmy £3000
fred £4000

I am using to courier font so the letter are equally spaced but don't know
how to format the spaces to take into account the different length of the
variables


Well, you have to first determine the widest acceptable size. Once this is
done, you can create a simple function such as this (this is one of the many
ways):

Function allign2Vars(v1$, v2$, colWidth)
Dim vw
vw = Len(v1$) + Len(v2$)
' trap for too small of a size
If ((colWidth \ 2) - Len(v1$)) < 1 Then
allign2Vars = v1$ & v2$
Else
allign2Vars = v1$ & String(colWidth \ 2 - Len(v1$), 32) & v2$
End If
End Function

To use it, simply pass the two vars and the limit width. Assuming you want
to not exceed 20 characters width:

a$ = "Jim": b$ = "Smith"
c$ = allign2Vars(a$, b$, 20)
List1.AddItem c$

a$ = "Susan": b$ = "Young"
c$ = allign2Vars(a$, b$, 20)
List1.AddItem c$
Jul 17 '05 #3
Thanks for the replies.
Very helpful
--
cheers dudes
************
kin®sole
************
"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:be*******************@nwrdny01.gnilink.net...

"Kin®sole" <ki******@NOSPAMhotmail.com> wrote in message
news:23******************************@news.teranew s.com...
Hi
I am trying to add two variables to a list box and keep everything in line.I
get the result below

Gaz £2000
Jimmy £3000
fred £4000

but would like to get this result
Gaz £2000
Jimmy £3000
fred £4000

I am using to courier font so the letter are equally spaced but don't know how to format the spaces to take into account the different length of the variables


Well, you have to first determine the widest acceptable size. Once this is
done, you can create a simple function such as this (this is one of the

many ways):

Function allign2Vars(v1$, v2$, colWidth)
Dim vw
vw = Len(v1$) + Len(v2$)
' trap for too small of a size
If ((colWidth \ 2) - Len(v1$)) < 1 Then
allign2Vars = v1$ & v2$
Else
allign2Vars = v1$ & String(colWidth \ 2 - Len(v1$), 32) & v2$
End If
End Function

To use it, simply pass the two vars and the limit width. Assuming you want
to not exceed 20 characters width:

a$ = "Jim": b$ = "Smith"
c$ = allign2Vars(a$, b$, 20)
List1.AddItem c$

a$ = "Susan": b$ = "Young"
c$ = allign2Vars(a$, b$, 20)
List1.AddItem c$

Jul 17 '05 #4
You want custom tab stops in a listbox ... and you might even want
right-aligned tabs as well.

Grab this tool http://vbnet.mvps.org/code/listapi/cooltabs.htm to generate
the code you need ... and read up on the code here:
http://vbnet.mvps.org/code/listapi/listboxtabs.htm

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Kin®sole" <ki******@NOSPAMhotmail.com> wrote in message
news:23******************************@news.teranew s.com...
: Hi
: I am trying to add two variables to a list box and keep everything in
line.I
: get the result below
:
: Gaz #2000
: Jimmy #3000
: fred #4000
:
: but would like to get this result
:
:
: Gaz #2000
: Jimmy #3000
: fred #4000
:
: I am using to courier font so the letter are equally spaced but don't know
: how to format the spaces to take into account the different length of the
: variables
:
: Any pointers
:
:
: --
: cheers dude
: ************
: kin.sole
: ************
:
:
:
:

Jul 17 '05 #5
Couldn't he just use the format command

List1.AddItem Format("Gaz", "!@@@@@@@@@@@@@@@") & "£2000"

This would give a 15 character block for the first part ("Gaz") and add the
value after

The "!" is needed because format automatically fills from the left, this
forces it to the right
Jul 17 '05 #6
That requires a fixed-width font for the text to align properly. The API
method actually sets tab stops at desired intervals thereby supporting the
default font or another such as truetype. Personally, I deem an application
as 'amateur' when a listbox must used a non-standard fixed-width font in
order to align its contents.
--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"Trevor Watson" <tr****@gatewaysoftware.ca> wrote in message
news:c8********************@look.ca...
: Couldn't he just use the format command
:
: List1.AddItem Format("Gaz", "!@@@@@@@@@@@@@@@") & "#2000"
:
: This would give a 15 character block for the first part ("Gaz") and add
the
: value after
:
: The "!" is needed because format automatically fills from the left, this
: forces it to the right
:
:

Jul 17 '05 #7

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

Similar topics

0
by: rodrigo guerra | last post by:
where i can change the code formating that visual studio does in the code.... like if i type: if ( ) { .... } visual studio changes to:
1
by: Marius | last post by:
I would like to format each row in a listbox (VBA - Access) according to a condition found on the same row. i.e: I want to grey-out all the customers called "John". Can this be done, for I have...
1
by: Neha Jain | last post by:
hi all, I have two forms Form_Field, Form_Criteria. First the "Form_field" is invoked.It contains a listbox wich give the field names of a table "Names". User is allowed to choose any nuber...
3
by: Smiley | last post by:
Hi, I know how to do confitional formating in Excel by clicking the wizard. Is this possible in MS Access ? If so, please directly where to look. I found example but nothing as to how to do it....
12
tolkienarda
by: tolkienarda | last post by:
hi all I am working on a content management service and i need some help keeping formating. what i am doing is recreating my site in an admin side and all of the articles on the site will...
1
by: Shawn Northrop | last post by:
I just read an article on kirupa.com about incorporating mySQL and PHP with flash. I am dynamically loading conent into a flash movie and am not sure how to format. In my php code i have: $y = "";...
0
by: Fonix | last post by:
I'm trying to make table border with pyExcelerator. As i can see there is only cell formating!? If i'm wrong pls tell me what is method to make more then one cell to have same format, other then...
2
by: sitko | last post by:
Hi, I'm in the process of converting a VB.net program into a C program so it can run on a unix like machine. I've been moving along at a nice pace, but this conversion has stumped me. I need...
6
by: sitko | last post by:
Hi, I've continued with my VB->C conversion, and have it working on the Linux box, now I'm going back and getting it to work on the Windows box. Something strange occurred and I thought I'd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.