Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

FileListBox or ListBox - Multiselect Problem

Posted on 2004-09-29
2
715 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

789 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