Results 1 to 4 of 4

Thread: RESOLVED - Return a String of Selected Items in Listbox

  1. #1

    Thread Starter
    Member Suidae's Avatar
    Join Date
    Nov 2001
    Posts
    52

    RESOLVED - Return a String of Selected Items in Listbox

    I have a listbox that is populated with years.

    2001 <-Selected
    2002 <-Selected
    2003
    2004 <-Selected
    2005

    I want to return a string based upon the selections made.

    Example: 2001,2002,2004

    Code:
        Dim z As Integer
        Dim Ystr as String
    
          For z = 0 To (lstForecastYears.ListCount - 1)
            If lstForecastYears.Selected(z) = True Then
                Ystr =  lstForecastYears.List(z)
            End If
                Msgbox Ystr
            Next
    I'm returning the correct selections but how do I get into a string format with the delimiters?

    Thanks.
    Last edited by Suidae; Jul 8th, 2003 at 05:14 PM.
    I'm a misanthropic philanthropist!
    Frog, the only white meat...

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Try this :

    VB Code:
    1. Dim z As Integer
    2.       Dim Ystr as String
    3.  
    4.       Ystr = ""
    5.  
    6.       For z = 0 To (lstForecastYears.ListCount - 1)
    7.         If lstForecastYears.Selected(z) = True Then
    8.             Ystr =  Ystr & lstForecastYears.List(z) & ","
    9.         End If
    10.       Next
    11.  
    12.       Ystr = Left$(Ystr, Len(Ystr) - 1) 'This is just to remove the last comma
    13.  
    14.       Msgbox Ystr
    Last edited by manavo11; Jul 8th, 2003 at 05:01 PM.


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

    Thread Starter
    Member Suidae's Avatar
    Join Date
    Nov 2001
    Posts
    52
    Perfect!

    Thank you!
    I'm a misanthropic philanthropist!
    Frog, the only white meat...

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    You're welcome


    Has someone helped you? Then you can Rate their helpful post.

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