Results 1 to 4 of 4

Thread: How to align items inside a list

  1. #1

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92

    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??????

  2. #2
    Guest
    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")

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    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.

    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width