Unicode Controls & Classes for VB6 - Version 4

clsCommDialogs.ShowSave Function

Creates a Save dialog box that lets the user specify the drive, directory, and name of a file to save.

Syntax
Public Function ShowSave (ByVal hwndParent As Long, _
ByVal sFilter As String, _
ByVal sTitle As String, _
ByRef lFlags As eOpenFileFlags, _
ByVal sStartDir As String, _
ByVal sDefaultFile As String, _
ByRef iFilterIndex As Integer, _
Optional ByVal sDefExt As String = "") As String
Parameters
Parameter Description
ByVal hwndParent As Long A handle to the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner.
ByVal sFilter As String The first string in each pair is a display string that describes the filter (for example, "Text Files"), and the second string specifies the filter pattern (for example, "*.TXT"). To specify multiple filter patterns for a single display string, use a semicolon to separate the patterns (for example, "*.TXT;*.DOC;*.BAK"). A pattern string can be a combination of valid file name characters and the asterisk (*) wildcard character. Do not include spaces in the pattern string.
ByVal sTitle As String A string to be placed in the title bar of the dialog box. If this member is NULL, the system uses the default title (that is, Save As or Open).
ByRef lFlags As eOpenFileFlags A combination of values of the [eOpenFileFlags] enum
ByVal sStartDir As String The initial directory. The algorithm for selecting the initial directory varies on different platforms.
ByVal sDefaultFile As String The default Filename searched for
ByRef iFilterIndex As Integer The index of the currently selected filter in the File Types control. The buffer pointed to by lpstrFilter contains pairs of strings that define the filters. The first pair of strings has an index value of 1, the second pair 2, and so on. An index of zero indicates the custom filter specified by lpstrCustomFilter. You can specify an index on input to indicate the initial filter description and filter pattern for the dialog box. When the user selects a file, nFilterIndex returns the index of the currently displayed filter. If nFilterIndex is zero and lpstrCustomFilter is NULL, the system uses the first filter in the lpstrFilter buffer. If all three members are zero or NULL, the system does not use any filters and does not show any files in the file list control of the dialog box.
Optional ByVal sDefExt As String = "" The default extension. GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension. This string can be any length, but only the first three characters are appended. The string should not contain a period (.). If this member is "" and the user fails to type an extension, no extension is appended.
Remarks
Returns the chosen filename
This code will open the SaveFile dialog
Private Sub mnuSave_Click()
Dim sFilter As String
Dim iFilterIndex As Integer
Dim s As String

sFilter = "All Text Files" + Chr(0) + "*.txt; *.js; *.htm; *.html; *.xml; *.asp; *.php; *.cfm; *.jsp; *.inc; *.vb; *.cs; *.frm; *.bas; *.c; *.cpp; *.diz; *.ini;" + Chr(0) & _
"Text File (*.txt)" + Chr(0) + "*.txt" + Chr(0) & _
"Script File (*.js)" + Chr(0) + "*.js" + Chr(0) & _
"HTML File (*.htm; *.html)" + Chr(0) + "*.htm; *.html" + Chr(0) & _
"XML File (*.xml)" + Chr(0) + "*.xml" + Chr(0) & _
"ASP File (*.asp)" + Chr(0) + "*.asp" + Chr(0) & _
"PHP File (*.php)" + Chr(0) + "*.php" + Chr(0) & _
"Cold Fusion File (*.cfm)" + Chr(0) + "*.cfm" + Chr(0) & _
"Java Server Page File (*.jsp)" + Chr(0) + "*.jsp" + Chr(0) & _
"Include (*.inc)" + Chr(0) + "*.inc" + Chr(0) & _
"All Files (*.*)" + Chr(0) + "*.*" + Chr(0)

s = moCommonDialog.ShowSave(Me.hWnd, sFilter, moMultiLngSupport.GGS("002", "Save File As..."), _
eOpenFileFlags.OFN_OVERWRITEPROMPT, App.Path, "myFile.txt", iFilterIndex)

'
'iFilterIndex is a variabled valorized by the ShowSave call
'and contains the index of the type of file chosen when saving
'for example:
' 1 --> All text Files
' 2 --> Text File (*.txt)
' 3 --> Script File
'Basing on the filter you pass for the function
'This parameter is optional
'
If Len(s) > 0 Then
moCommonWrapper.ShowMessageBoxW s, , App.Title & " " & iFilterIndex
End If

End Sub