Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filtering a filelistbox

Status
Not open for further replies.

orisons

Programmer
Feb 18, 2002
49
CA
how do I filter the file list box to show only excel file types (with the option to show all file types if necessary)

Code:
Dim mFileSysObj As New FileSystemObject
Private Sub dir_Dirbox_Change()
    fil_Filebox.Path = dir_Dirbox.Path 'updates the file path to the directory path
End Sub

Private Sub drv_Drivebox_Change()
On Error GoTo patherror

    'update the directory path to the drive
    dir_Dirbox.Path = drv_Drivebox.Drive
    Exit Sub

End Sub

Private Sub fil_Filebox_Click()
Call displayData 'this updates the textbox

End Sub
Private Sub displayData()
    txt_path.Text = "" 'clears text box
    txt_path.Text = "Path Name: " & mFileSysObj.GetAbsolutePathName(fil_Filebox.Path)
    'Gets path name and assigns it as a string to txt_path text box
    
End Sub
anyhelp would be much appriciated.

 
use the .pattern property

FileListBox.Pattern="*.csv; *.xls"

If somethings hard to do, its not worth doing - Homer Simpson
 
To show only Excel workbooks:

fil_Filebox.Pattern = "*.xls"

To show all files:

fil_Filebox.Pattern = "*.*"

To show multiple file types (for example, Excel workbooks and Word docs):

fil_Filebox.Pattern = "*.xls;*.doc"


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Thank you all its working a treat, but one question is there any way I can place a dropdown box with options for different file extensions (I know I can do it in vba but I am new to vb)
 
u could add a combo box, and update the pattern there.

If somethings hard to do, its not worth doing - Homer Simpson
 
By the way, I don't recommend the use of the New keyword on the same line as the declaration statement, in all but a very few circumstances. The reason for this is that the compiler doesn't actually instantiate the object on the Dim line, but rather implicitly instantiates it when you reference it later in the code. As such, the compiler doesn't know at runtime know if the object has been instantiated yet whenever you reference it in your code, so it has to look for an instance and then create one if it doesn't find one. This is inefficient, of course. It's generally better therefore to use "Set MyObject = New MyClass" on a separate line.

A possible exception to this is in a situation where there are very few references to the object, and the object is only instantiated some of the time. In this case, more efficiency might derive from saving the overhead required for the explicit instantiation.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top