Article ID: 106682
Article Last Modified on 1/8/2003
Sub Form_Load ()
' Enter the following two lines as one, single line:
CMDialog1.Filter = "Text Files *.Txt|*.Txt|Basic Files *.Bas|*.Bas|
All Files *.*|*.*"
CMDialog1.FilterIndex = 1 'Sets default filter to *.txt.
CMDialog1.DefaultExt = "TXT" 'Default extension if you enter none.
' In the dialog box, the default extension will be applied only if you
' enter the filename with no period. If you type the file name with
' a period and no extension (such as FILEX.), then CMDialog1.Filename
' always returns a blank extension.
' Set the common dialog Action property to 1 to execute the File Open
' dialog or 2 to execute the File Save As dialog:
CMDialog1.Action = 1 ' 1=Invokes the File Open common dialog box.
' Limitation: The value of FilterIndex doesn't change even if you change
' the file type in the Open common dialog box:
Debug.Print CMDialog1.FilterIndex
' The Filename property displays the filename and path that you entered
' in the Open dialog:
Debug.Print CMDialog1.Filename 'Prints filename with path prefix
' Debug.Print CMDialog1.Filetitle 'Prints filename without path
End Sub
nFilterIndex:
Specifies an index into the buffer pointed to by the lpstrFiler member.
The system uses the index value to obtain a pair of strings to use as
the initial filter description and filter pattern for the dialog box.
The first pair of strings has an index value of 1. When the user chooses
the OK button to close the dialog box, the system copies the index of
the selected filter strings into this location. If the nFilterIndex
member is 0, the filter in the buffer pointed to by the
lpstrCustomFilter member is used. If the nFilterIndex member is 0 and
the lpstrCustomFilter member is NULL, the system uses the first filter
in the buffer pointed to by the lpstrFilter member. If each of the three
members is either 0 or NULL, the system does not use any filters and
does not show any files in the File Name list box of the dialog box.
Additional query words: 2.00 3.00 4.00 vb416 vb4win
Keywords: kbprb KB106682