|
-
Aug 16th, 2001, 10:29 PM
#1
Thread Starter
Lively Member
Filtering unique items
I've got a FileListBox in which I'm displaying all the files in a directory. I'd like to allow the user to filter files based on the existing (displayed) file exentensions. I've succeeded in doing this but it's very slow on directories with a lot of files. Basically I've populated a dynamic array with all extensions then pull one out, cycle through looking for duplicates, then go to the next one. I then add the unique extensions to a Combo Box. I know there's got to be a better and faster way. Any help is much appreciated! Thanks!
-
Aug 16th, 2001, 10:45 PM
#2
Check out the Pattern property of the FileListBox. Is that what you are talking about?
-
Aug 17th, 2001, 03:02 AM
#3
Retired VBF Adm1nistrator
Well if you want to do duplicate checking there's nothing faster than the Dictionary object in the Microsoft Scripting Runtime reference.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 17th, 2001, 04:18 PM
#4
So what is the code you are using to get the unique file extensions?
-
Aug 17th, 2001, 04:34 PM
#5
Here is how I'd do it:
VB Code:
Option Explicit
'declares to check combo
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_FINDSTRING = &H14C
Private Const CB_FINDSTRINGEXACT = &H158
Private Sub FillCombo()
Dim fso As FileSystemObject
Set fso = New FileSystemObject
Dim fldr As Folder
Dim fle As File
'clear contents of combo
Combo1.Clear
'get the folder
Set fldr = fso.GetFolder(File1.Path)
'loop thru files
For Each fle In fldr.Files
Dim cbi As Integer
'test the extension against the combo
cbi = SendMessage(Combo1.hWnd, CB_FINDSTRINGEXACT, 0, ByVal fso.GetExtensionName(fle.Name))
If cbi = -1 Then
'it is a new extension so add it
Combo1.AddItem fso.GetExtensionName(fle.Name)
End If
Next
Set fldr = Nothing
Set fle = Nothing
Set fso = Nothing
End Sub
Private Sub Combo1_Click()
'change pattern to selected
If Combo1.Text <> "" Then
File1.Pattern = "*." & Combo1.Text
End If
End Sub
Private Sub File1_PathChange()
'path changed refill combo
FillCombo
End Sub
Private Sub Form_Load()
'fill combo
FillCombo
End Sub
This assumes a reference to the Microsoft Scripting Runtime (for the FileSystemObject), a FileListBox (File1), a Combobox (Combo1)
-
Aug 20th, 2001, 01:59 AM
#6
Retired VBF Adm1nistrator
I'll say it again, the Dictionary object is the fastest at keeping unique lists.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|