Solved

FileListBox or ListBox - Multiselect Problem

Posted on 2004-09-29
2
724 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
[X]
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
2 Comments
 
LVL 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

724 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