Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Filter files with these extensions (File Dialog Box)

Posted on 2001-06-11
3
Medium Priority
?
222 Views
Last Modified: 2010-05-02
Hi again,

VB6 (sp4) ADO

I have two concerns. I want to display all files with these extensions: *.htm and *html in my file dialog box, and I want to check to see if the proper file extension was selected before I save its location to the Windows registry. Thanks for your help (as always).

With frmOptions.cd_Options
      .DialogTitle = "Connect to application's back-end database."
      .InitDir = "C:\DS3VB6\DS3_DATA\"
      .FileName = "" 'App_BackEndDBName
      .Filter = "Access (*.mdb)| *.mdb"
      .CancelError = True 'Causes an error if user clicks on cancel
      .ShowOpen
    End With
'Remember that the file names are case sensitive
    Do While UCase(Right(Trim(frmOptions.cd_Options.FileName), Len("DS3DATA.MDB"))) <> "DS3DATA.MDB"
      MsgBox "You are trying to link to the wrong file.", vbCritical, App.Title
      frmOptions.cd_Options.ShowOpen
    Loop
      App_InventoryPath = Trim(frmOptions.cd_Options.FileName)
      frmOptions.txtInventoryPath = App_InventoryPath
    'Save the Database location
    SaveSetting App.Title, "App_Elements", "InventoryPath_DB", App_InventoryPath


-ADawn
0
Comment
Question by:ADawn
[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
3 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6179208
To limit the users to HTML files:
.Filter = "HTML Files (*.HTML, *.HTM)|*.html;*.htm"

To check the type (place this right after the line of code to show the dialog:
If Right$(UCase(CommonDialog1.FileName), 4) <> "HTML" Or Right$(UCase(CommonDialog1.FileName), 3) <> "HTM" Then
  MsgBox "Invalid Selection!", vbCritical, "Error"
  Exit Sub
Else
  'Write to registry
End If
0
 
LVL 6

Expert Comment

by:JonFish85
ID: 6179211
er, change the ...<> "HTML" Or Right$... to ...<> "HTML" And Right$...
0
 
LVL 2

Accepted Solution

by:
TravisHall earned 80 total points
ID: 6179341
Jon's checking code is okay, but it would recognise a longer file extension ending in HTML or HTM as valid, when it isn't. For example, "somefile.chtml" would pass the test, and it shouldn't. To modify that code slightly:

If Right$(UCase(CommonDialog1.FileName), 5) <> ".HTML" Or Right$(UCase(CommonDialog1.FileName), 4) <> 
".HTM" Then
 MsgBox "Invalid Selection!", vbCritical, "Error"
 Exit Sub
Else
 'Write to registry
End If

That would fix that case, and also the case when the full file name is "somethinghtml" (which has no extension).

However, it should also be noted that all file names selected when using the appropriate filter must match that filter. That's what the filter is for. I guess there are times when one should not assume that things will work the way they are supposed to, but that does seem a little too paranoid to me, for the general case.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses

721 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