Results 1 to 4 of 4

Thread: List Box help

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    48

    Angry List Box help

    Hi all

    I've got a listbox that is already sorted as below.

    1234 Williams Mr
    1121 Henderson Mrs
    0983 Harris J
    0765 Thomas

    I now want the list box or another to show the following.

    1. Williams Mr 1234
    2. Henderson Mrs 1121
    3. Harris J 0983
    4. Thomas 0765

    Thanks
    Rob

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    VB Code:
    1. Dim temp() As String
    2.         Dim newlist() As String
    3.         Dim I As Integer
    4.         Dim x As Integer
    5.         ReDim newlist(ListBox1.Items.Count - 1)
    6.         For x = 0 To ListBox1.Items.Count - 1
    7.             temp = Split(ListBox1.Items.Item(x), " ")
    8.             For I = 1 To UBound(temp)
    9.                 newlist(x) = newlist(x) & temp(I) & " "
    10.             Next
    11.             newlist(x) = newlist(x) & temp(0)
    12.         Next
    13.         ListBox1.Items.Clear()
    14.         For x = 0 To UBound(newlist)
    15.             ListBox1.Items.Add(newlist(x))
    16.         Next

    thats quick off the top of my head...probably can be done differently(better) but it works...

    Basically splits each line up...then swaps the numbers (first part) to the end...

    let me know if that works for you
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    VB Code:
    1. Dim i As Integer, s As String
    2.         For i = 0 To Listbox1.Items.Count - 1
    3.             s = ListBox1.Items.Item(i).ToString
    4.             Listbox1.Items.Item(i) = (i + 1).ToString & "." & s.Remove(0, Len(s.Split(" ")(0))) & " " & s.Split(" ")(0)
    5.         Next

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    see? i knew it had to be able to be done easier..

    very nice Lunatic.

    (I forgot to add the 1. 2. etc... )
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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