Solved

FileListBox or ListBox - Multiselect Problem

Posted on 2004-09-29
2
702 Views
Last Modified: 2013-12-26
One of the components of my GUI project is that I currently have a FileListBox that I need the user to be able to select multiple files from. I have the code in place to examine an array populated with the FileListBox contents and another array gets created of only the files that are selected. I have this functionality working fine, when the files are selected from top to bottom within the filelistbox contents, in other words in the same numerical order as the indexing. But If file selections are made in any other order, (bottom to top, or random) only the last file (or files selected, that coincide with indexing) get selected and thus get enumerated in the second array.

Is there a way to get the selected files from the FileListBox regardless of what order they are selected?

       
0
Comment
Question by:boris711
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 12184148
How about this approach?

Option Explicit

' holds the names of the selected files
Private selectedFiles As Collection

Private Sub Form_Load()
    File1.Path = "c:\"
End Sub

' building the collection of selected files...
Private Sub Command1_Click()
    Dim i As Integer
   
    Set selectedFiles = New Collection
    For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
            selectedFiles.Add File1.List(i)
        End If
    Next i  
End Sub

' enumerating the collection of selected files...
Private Sub Command2_Click()
    Dim curFile As Variant
   
    If Not (selectedFiles Is Nothing) Then
        For Each curFile In selectedFiles
            Debug.Print curFile
        Next
    End If
End Sub
0
 
LVL 1

Author Comment

by:boris711
ID: 12184586
That worked perfect!

I am relativly new to programming, and hadn't thought of using a collection vs. an array.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now