Solved

Filter files with these extensions (File Dialog Box)

Posted on 2001-06-11
3
211 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
  • 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 20 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now