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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re: Common Dialog FAQ

Status
Not open for further replies.
Jan 9, 2003
147
US
Hi,

When using the common dialog control found on:

Shouldn't the common dialog return the filename and the extension when ShowSave is called? Or am I just doing something stupid here...

Here's the code I use when calling:
Code:
Dim cdl As New clsCommonDialog
Dim strFileName As String    'full file name

cdl.Filter = "Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"

'this is where the dialog opens
cdl.ShowSave

strFileName = cdl.FileName

'hence no len, no name...
If Len(strFileName) = 0 Then Exit Sub

MsgBox (strFileName)

The filter works properly, changing the dropdown in the save dialog changes the list of files, but if I enter a filename with no extension, then click save, the FileName property contains the path and "filename", but no extension. This isn't how I remember the Common Dialog from VB6 working. Or am I having a Brain Fart.

I guess I can get at the FilterIndex property and find out what extension was chosen...

Thanks,
Andrew
 
Your filter has more than one extension.
Which one is the default extension?

I just tried out the FAQ code, and it all works if:

You add the following line before the ShowSave
Code:
cmdlgOpenFile.DefaultExt = "JIM"
..and have an 'All Files *.*' file type.

If I enter a filename with no extension while the type is BAT, I get BAT
If I do it when using *.*, I get filename.JIM

 
Yes, that appears to have done it. I didn't realize that I had to set the Default Extension as well.

Thanks Jeff,

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top