|
-
Nov 18th, 2000, 07:34 PM
#1
Thread Starter
Lively Member
HELP NOW NOW!!!!
How to align items inside a list, how can this be done simply
if i am adding a name and a phone number, then obviously lenghts will vary and the phone numberts won't align with the rest of them in the list so how do i align them
original list:
Billy Bob 556-7895
Bobby 456-7895
Jim 123-7845
Timy Boy 789-4563
aftert aligned:
a = space
Billyaaaa556-7895
Bobbyaaaa456-7895
Jimaaaaaa123-7845
Timyaaaaaa789-4562
please explain how??????
-
Nov 18th, 2000, 10:08 PM
#2
You could use the Space() function or Spc() function (same thing).
Msgbox "Hello" & Space(10) & "World"
Or the Tab() function.
Msgbox "Hello" & vbTab & "World"
(or like this: Msgbox "Hello" & vbTab(10) & "World")
-
Nov 18th, 2000, 10:44 PM
#3
PowerPoster
-
Nov 18th, 2000, 10:46 PM
#4
Well ...
I am not sure whether a ListBox is a place to display a multi-column list properly aligned at all columns, you can use the ListView control for that.
Anyway if you insist upon using the ListBox, here are a few tips.
First and foremost, set the font of the ListBox to Courier or such other fixed lenght font, sothat your alignment efforts are not thrown out of gear by the font.
Secondly, decide how many columns you are going to display and what should be their individual widths.
Now set up the code like this:
Code:
' I am assuming two columns, from your example.
' Name, Ph are variables which will store each column data.
' I also assume the width of the name column is 20,
' while phone numbers will have 15 (although I know it will
' not be more than 12.)
List1.AddItem Name & Space(20 - Len(Name)) & Ph & Space(15-Len(Ph))
The above statement will left-align both the columns. If you want the phone numbers to be right-aligned, use the statement:
Code:
List1.AddItem Name & Space(20 - Len(Name)) & Space(15-Len(Ph)) & Ph
Replace the above numbers 20 and 15 with the desired column widths. If you have more columns, join them to the string with additional '&' symbols.
Remember, adding each column has two parts, adding the data and adding the required number of spaces.
While extracting from the ListBox, you can separate the two column values with this:
Code:
MsgBox "Name is: " & Trim(Left(List1.Text,20))
MsgBox "Phone is: " & Trim(Right(List1.Text,15))
Since we have only two columns, the extraction procedure looks simple, but with more than two columns, you may need to use the MID function and have a good programming design in place to maintain the code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|