Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Common Dialogs Code Examples

Displaying The Common Save Dialog

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
Displaying The Common Save Dialog 'The API Function. Public Declare Function GetSaveFileName Lib "comdlg32.dll" _ Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long 'Now come some Types. Public Enum GFNFlags OFN_ALLOWMULTISELECT = &H200 OFN_CREATEPROMPT = &H2000 OFN_EXPLORER = &H80000 OFN_FILEMUSTEXIST = &H1000 OFN_HIDEREADONLY = &H4 OFN_LONGNAMES = &H200000 OFN_NOCHANGEDIR = &H8 OFN_NODEREFERENCELINKS = &H100000 OFN_NOLONGNAMES = &H40000 OFN_NONETWORKBUTTON = &H20000 OFN_NOREADONLYRETURN = &H8000 OFN_NOTESTFILECREATE = &H10000 OFN_NOVALIDATE = &H100 OFN_OVERWRITEPROMPT = &H2 OFN_PATHMUSTEXIST = &H800 OFN_READONLY = &H1 End Enum Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String Flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type 'This is the wrapper Function. Public Function SaveDialog(ByVal OwnerhWnd As Long, _ ByVal Filters As String, ByVal FilterIndex As Long, _ ByVal FNameLength As Long, _ Optional ByVal InitFolder As String = "", _ Optional ByVal InitFileName As String = "", _ Optional ByVal dlgTitle As String = "", _ Optional ByVal Flags As GFNFlags = 0) As String 'Dimension some variables. Dim GFN As OPENFILENAME 'Sort out some of the Type we will pass. GFN.lStructSize = Len(GFN) GFN.hwndOwner = OwnerhWnd GFN.hInstance = App.hInstance 'Sort out the filters. For I = 1 To Len(Filters) If Mid$(Filters, I, 1) = "|" Then Filters = Left$(Filters, I - 1) & Chr$(0) & _ Right$(Filters, Len(Filters) - I) End If Next 'Finish setting up the Type. GFN.lpstrFilter = Filters GFN.nFilterIndex = FilterIndex GFN.lpstrFile = InitFileName & String$(FNameLength - Len(InitFileName), Chr$(0)) GFN.nMaxFile = FNameLength GFN.lpstrFileTitle = String$(FNameLength, Chr$(0)) GFN.nMaxFileTitle = FNameLength GFN.lpstrInitialDir = InitFolder GFN.lpstrTitle = dlgTitle GFN.Flags = Flags 'Get and return the filename. If GetSaveFileName(GFN) >= 1 Then SaveDialog = GFN.lpstrFile Else SaveDialog = Chr$(0) End If End Function