How to add selected Items into a collection

Do you know how to add all selected items from List into a collection?
Please write codes in detail! Thanks!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

  I'm not sure what type of collection you are trying to place your results into, but here is a short and simple program that you could probably modify to suit your needs.  If you have any problems, let me know!

1) Create a form with a listbox, a textbox, and a command button.

2) For demonstration purposes, we'll use the default names of each control.

3) Change the MultiSelect property of the listbox to either "1-Simple" or "2-Extended"

4) Add the following code:

Option Explicit
Dim x As Integer

Private Sub Command1_Click()

    Text1.Text = ""
    For x = 0 To List1.ListCount - 1
        If List1.Selected(x) Then
            List1.ListIndex = x
            Text1.Text = Text1.Text & vbCr & List1.Text
        End If
    Next x
End Sub

Private Sub Form_Load()
    For x = 1 To 10
        List1.AddItem (CStr(x))
    Next x
End Sub

   This short program will populate your listbox with numbers 1 thru 10.  Select any of the numbers and click the command button.  Your selected items will appear in the textbox!  Modify this code to place the value(s) into an array, user type, etc.

Good luck!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.