none
Using Open / Save File Dialogues from within a Module RRS feed

  • Question

  • I am working on an application that has 5 forms and 1 module.

    The module is to contain the Subs and Functions shared by some or all of the forms. A few of the Subs need to invoke a Save / Open File Dialogue, but you can't add a dialogue to a module.

    Am I wrong, or is there a way I can use Dialogues from within a module?

    Thank in advance.

    Thursday, May 18, 2017 1:53 PM

Answers

  • Hello,

    Here is a pattern where all dialog operations are done in a class under My NameSpace and used no different than

    My.Computer.FileSystem.DeleteFile("SomeFile.txt")

    Here is the custom class (with a few extra functions) See more in my MSDN code sample.

    Imports System.IO
    
    Namespace My
        <ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
        Partial Friend Class _Dialogs
            Private mException As Exception
            Public ReadOnly Property Exception As Exception
                Get
                    Return mException
                End Get
            End Property
            Private mHasException As Boolean
            Public ReadOnly Property HasException As Boolean
                Get
                    Return mHasException
                End Get
            End Property
    
            Public Function SelectTextFile(ByVal InitialDirectory As String, ByRef FileName As String) As Boolean
                Using dialog As New OpenFileDialog With {.InitialDirectory = InitialDirectory, .Filter = "txt files (*.txt)|*.txt"}
                    If dialog.ShowDialog = DialogResult.OK Then
                        FileName = dialog.FileName
                        Return True
                    End If
                End Using
                Return False
            End Function
            Public Function SelectFile(ByVal InitialDirectory As String, ByVal Filter As String, ByRef FileName As String) As Boolean
                Using dialog As New OpenFileDialog With {.InitialDirectory = InitialDirectory, .Filter = Filter}
                    If dialog.ShowDialog = DialogResult.OK Then
                        FileName = dialog.FileName
                        Return True
                    End If
                End Using
                Return False
            End Function
            Public Function SaveTextFile(ByVal InitialDirectory As String, ByVal Contents As String()) As Boolean
                Using dialog As New SaveFileDialog With {.InitialDirectory = InitialDirectory}
                    If dialog.ShowDialog = DialogResult.OK Then
                        Try
                            File.WriteAllLines(dialog.FileName, Contents)
                            Return True
                        Catch ex As Exception
                            mException = ex
                            mHasException = True
                            Return False
                        End Try
                    End If
                End Using
                Return False
            End Function
            Public Function Question(ByVal Text As String) As Boolean
                Return (MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = MsgBoxResult.Yes)
            End Function
            Public Function Question(ByVal Text As String, ByVal Title As String, ByVal DefaultButton As MsgBoxResult) As Boolean
                Dim db As MessageBoxDefaultButton
                If DefaultButton = MsgBoxResult.No Then
                    db = MessageBoxDefaultButton.Button2
                End If
                Return (MessageBox.Show(Text, Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, db) = MsgBoxResult.Yes)
            End Function
            Public Sub InformationDialog(ByVal Text As String)
                MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Sub
            Public Sub WarningDialog(ByVal Text As String)
                MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Sub
            Public Sub ExceptionDialog(ByVal Text As String)
                MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Sub
        End Class
        <HideModuleName()>
        Friend Module KarenPayne_Dialogs
            Private instance As New ThreadSafeObjectProvider(Of _Dialogs)
            ReadOnly Property Dialogs() As _Dialogs
                Get
                    Return instance.GetInstance()
                End Get
            End Property
        End Module
    End Namespace

    Simple usage in a code module

    Module Module1
        Public Sub Demo1()
            Dim FileName As String = ""
            If My.Dialogs.SelectTextFile("C:\Data", FileName) Then
                MessageBox.Show(FileName)
            End If
        End Sub
        Public Sub Demo2()
            Dim fileContents As String() = {"Karen", "Jim", "Sue"}
            If My.Dialogs.SaveTextFile("C:\SomeFolder", fileContents) Then
                My.Dialogs.InformationDialog("Success")
            Else
                If My.Dialogs.HasException Then
                    My.Dialogs.ExceptionDialog($"Failed to save.{Environment.NewLine}{My.Dialogs.Exception.Message}")
                End If
            End If
        End Sub
    End Module
    

    Class overview


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by dw80916 Wednesday, July 5, 2017 10:03 PM
    Wednesday, May 24, 2017 12:55 PM
    Moderator
  • DW,

    I'll add the following for consideration - a class which has shared methods:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    ''' <summary>
    ''' One thing to remember about a SaveFileDialog and an OpenFileDialog 
    ''' is that neither of them do what their name suggests! They each allow 
    ''' the developer to show the user a way to select a file path, but they 
    ''' don't "open" or "save" anything; that's up to your code to do.
    ''' </summary>
    ''' <remarks></remarks>
    Public NotInheritable Class CommonFileDialogs
        ''' <summary>
        ''' A shared method which will return the file path that the user 
        ''' has selected. Be sure to test whether or not the return value 
        ''' is null.
        ''' </summary>
        ''' <param name="initialDirectory">The initial directory that this dialog 
        ''' should use.</param>
        ''' <param name="filter">OPTIONAL: A string set up for the file filter. 
        ''' Default: Null.</param>
        ''' <param name="defaultExtension">OPTIONAL: A string which will become 
        ''' the default file extension. Be sure to NOT include the dot. Default: 
        ''' Null.</param>
        ''' <param name="title">OPTIONAL: A title to present to the user. Default: 
        ''' Null.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function _
            SaveFileDialog(ByVal initialDirectory As String, _
                           Optional ByVal filter As String = Nothing, _
                           Optional ByVal defaultExtension As String = Nothing, _
                           Optional ByVal title As String = Nothing) As String
    
            Dim retVal As String = Nothing
    
            If Not String.IsNullOrWhiteSpace(initialDirectory) Then
                Dim di As New IO.DirectoryInfo(initialDirectory)
    
                If di.Exists Then
                    Using sfd As New SaveFileDialog
                        With sfd
                            .InitialDirectory = di.FullName
    
                            If Not String.IsNullOrWhiteSpace(filter) Then
                                .Filter = filter.Trim
                                .FilterIndex = 1
                            End If
    
                            If Not String.IsNullOrWhiteSpace(defaultExtension) Then
                                .AddExtension = True
                                .DefaultExt = defaultExtension.Trim
                            End If
    
                            If Not String.IsNullOrWhiteSpace(title) Then
                                .Title = title.Trim
                            End If
    
                            .CheckFileExists = True
                            .CheckPathExists = True
                        End With
    
                        If sfd.ShowDialog = DialogResult.OK Then
                            retVal = sfd.FileName
                        End If
                    End Using
                End If
            End If
    
            Return retVal
    
        End Function
    
        ''' <summary>
        ''' A shared method which will return the file path that the user selected. 
        ''' Be sure to test whether or not the return value is null.
        ''' </summary>
        ''' <param name="initialDirectory">The initial directory that this dialog 
        ''' should use.</param>
        ''' <param name="filter">OPTIONAL: A string set up for the file filter. 
        ''' Default: Null.</param>
        ''' <param name="title">OPTIONAL: A title to present to the user. Default: 
        ''' Null.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function _
            OpenFileDialog_SingleFileSelect(ByVal initialDirectory As String, _
                                            Optional ByVal filter As String = Nothing, _
                                            Optional ByVal title As String = Nothing) As String
    
            Dim retVal As String = Nothing
    
            If Not String.IsNullOrWhiteSpace(initialDirectory) Then
                Dim di As New IO.DirectoryInfo(initialDirectory)
    
                If di.Exists Then
                    Using ofd As New OpenFileDialog
                        With ofd
                            .Multiselect = False
                            .InitialDirectory = di.FullName
    
                            If Not String.IsNullOrWhiteSpace(filter) Then
                                .Filter = filter.Trim
                                .FilterIndex = 1
                            End If
    
                            If Not String.IsNullOrWhiteSpace(title) Then
                                .Title = title.Trim
                            End If
                        End With
    
                        If ofd.ShowDialog = DialogResult.OK Then
                            retVal = ofd.FileName
                        End If
                    End Using
                End If
            End If
    
            Return retVal
    
        End Function
    
        ''' <summary>
        ''' A shared method which will return the file paths (as a string array) that 
        ''' the user selected. Be sure to test whether or not the return value is null.
        ''' </summary>
        ''' <param name="initialDirectory">The initial directory that this dialog 
        ''' should use.</param>
        ''' <param name="filter">OPTIONAL: A string set up for the file filter. 
        ''' Default: Null.</param>
        ''' <param name="title">OPTIONAL: A title to present to the user. Default: 
        ''' Null.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function _
            OpenFileDialog_MultiFileSelect(ByVal initialDirectory As String, _
                                           Optional ByVal filter As String = Nothing, _
                                           Optional ByVal title As String = Nothing) As String()
    
            Dim retVal As String() = Nothing
    
            If Not String.IsNullOrWhiteSpace(initialDirectory) Then
                Dim di As New IO.DirectoryInfo(initialDirectory)
    
                If di.Exists Then
                    Using ofd As New OpenFileDialog
                        With ofd
                            .Multiselect = True
                            .InitialDirectory = di.FullName
    
                            If Not String.IsNullOrWhiteSpace(filter) Then
                                .Filter = filter.Trim
                                .FilterIndex = 1
                            End If
    
                            If Not String.IsNullOrWhiteSpace(title) Then
                                .Title = title.Trim
                            End If
                        End With
    
                        If ofd.ShowDialog = DialogResult.OK Then
                            retVal = ofd.FileNames
                        End If
                    End Using
                End If
            End If
    
            Return retVal
    
        End Function
    End Class

    Example Usage:

    Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load ' My suggestion is to add a class to your project ' which has shared methods. If you're not sure ' how, it's as simple as right-clicking in ' Solution Explorer and choosing "Add" >> "Class". ' ' The name of my class is "CommonFileDialogs" and ' I'll show the code in the forum. ' ' The following shows how you might use this from ' any form in your project: ShowExample() Stop End Sub Private Sub ShowExample() Dim myDocuments As String = _ Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) If CommonFileDialogs.SaveFileDialog(myDocuments) IsNot Nothing Then Stop End If End Sub End Class



    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Wednesday, May 24, 2017 11:15 PM ...forgot to include the screenshot
    • Marked as answer by dw80916 Wednesday, July 5, 2017 10:03 PM
    Wednesday, May 24, 2017 11:07 PM

All replies

  • Hi dw80916,

    I'm sorry for the late reply.

    Please refer to the code below.

    Imports System.IO
    
    Module Module2
        Public Sub openfile()
            Dim myStream As Stream = Nothing
            Dim openFileDialog1 As New System.Windows.Forms.OpenFileDialog()
            openFileDialog1.InitialDirectory = "c:\"
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            openFileDialog1.FilterIndex = 2
            openFileDialog1.RestoreDirectory = True
    
            If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
                Try
                    myStream = openFileDialog1.OpenFile()
                    If (myStream IsNot Nothing) Then
                        ' Insert code to read the stream here.
                    End If
                Catch Ex As Exception
                    MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
                Finally
                    ' Check this again, since we need to make sure we didn't throw an exception on open.
                    If (myStream IsNot Nothing) Then
                        myStream.Close()
                    End If
                End Try
            End If
    
        End Sub
    End Module
    Public Class Form15
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            Module2.openfile()
        End Sub
    End Class

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, May 24, 2017 3:20 AM
    Moderator
  • Hallo DW,

    It is easy and than not only in an old style memory consuming module like it was before VB7 but in an OOP Class which consumes only memory if it is needed. 

    However, the Dialogs are modules itself which exist completely inside Windows, it even stores the last use.

    If you create your own module or class upon it, it is only an extra pass and slows down and consumes memory.

    In .Net is the Class which you want to build allready available, it exist from a kind of interface (not an Interface) to that Win32 dialog.

    It can be that you only has some fixed filter, Filter Index and other fixed setting likewise in the sample of Cherry. But for that is a much easier solution.

     


    Success
    Cor

    Wednesday, May 24, 2017 9:20 AM
  • Hello,

    Here is a pattern where all dialog operations are done in a class under My NameSpace and used no different than

    My.Computer.FileSystem.DeleteFile("SomeFile.txt")

    Here is the custom class (with a few extra functions) See more in my MSDN code sample.

    Imports System.IO
    
    Namespace My
        <ComponentModel.EditorBrowsable(ComponentModel.EditorBrowsableState.Never)>
        Partial Friend Class _Dialogs
            Private mException As Exception
            Public ReadOnly Property Exception As Exception
                Get
                    Return mException
                End Get
            End Property
            Private mHasException As Boolean
            Public ReadOnly Property HasException As Boolean
                Get
                    Return mHasException
                End Get
            End Property
    
            Public Function SelectTextFile(ByVal InitialDirectory As String, ByRef FileName As String) As Boolean
                Using dialog As New OpenFileDialog With {.InitialDirectory = InitialDirectory, .Filter = "txt files (*.txt)|*.txt"}
                    If dialog.ShowDialog = DialogResult.OK Then
                        FileName = dialog.FileName
                        Return True
                    End If
                End Using
                Return False
            End Function
            Public Function SelectFile(ByVal InitialDirectory As String, ByVal Filter As String, ByRef FileName As String) As Boolean
                Using dialog As New OpenFileDialog With {.InitialDirectory = InitialDirectory, .Filter = Filter}
                    If dialog.ShowDialog = DialogResult.OK Then
                        FileName = dialog.FileName
                        Return True
                    End If
                End Using
                Return False
            End Function
            Public Function SaveTextFile(ByVal InitialDirectory As String, ByVal Contents As String()) As Boolean
                Using dialog As New SaveFileDialog With {.InitialDirectory = InitialDirectory}
                    If dialog.ShowDialog = DialogResult.OK Then
                        Try
                            File.WriteAllLines(dialog.FileName, Contents)
                            Return True
                        Catch ex As Exception
                            mException = ex
                            mHasException = True
                            Return False
                        End Try
                    End If
                End Using
                Return False
            End Function
            Public Function Question(ByVal Text As String) As Boolean
                Return (MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = MsgBoxResult.Yes)
            End Function
            Public Function Question(ByVal Text As String, ByVal Title As String, ByVal DefaultButton As MsgBoxResult) As Boolean
                Dim db As MessageBoxDefaultButton
                If DefaultButton = MsgBoxResult.No Then
                    db = MessageBoxDefaultButton.Button2
                End If
                Return (MessageBox.Show(Text, Title, MessageBoxButtons.YesNo, MessageBoxIcon.Question, db) = MsgBoxResult.Yes)
            End Function
            Public Sub InformationDialog(ByVal Text As String)
                MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Information)
            End Sub
            Public Sub WarningDialog(ByVal Text As String)
                MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Sub
            Public Sub ExceptionDialog(ByVal Text As String)
                MessageBox.Show(Text, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Sub
        End Class
        <HideModuleName()>
        Friend Module KarenPayne_Dialogs
            Private instance As New ThreadSafeObjectProvider(Of _Dialogs)
            ReadOnly Property Dialogs() As _Dialogs
                Get
                    Return instance.GetInstance()
                End Get
            End Property
        End Module
    End Namespace

    Simple usage in a code module

    Module Module1
        Public Sub Demo1()
            Dim FileName As String = ""
            If My.Dialogs.SelectTextFile("C:\Data", FileName) Then
                MessageBox.Show(FileName)
            End If
        End Sub
        Public Sub Demo2()
            Dim fileContents As String() = {"Karen", "Jim", "Sue"}
            If My.Dialogs.SaveTextFile("C:\SomeFolder", fileContents) Then
                My.Dialogs.InformationDialog("Success")
            Else
                If My.Dialogs.HasException Then
                    My.Dialogs.ExceptionDialog($"Failed to save.{Environment.NewLine}{My.Dialogs.Exception.Message}")
                End If
            End If
        End Sub
    End Module
    

    Class overview


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by dw80916 Wednesday, July 5, 2017 10:03 PM
    Wednesday, May 24, 2017 12:55 PM
    Moderator
  • DW,

    I'll add the following for consideration - a class which has shared methods:

    Option Strict On
    Option Explicit On
    Option Infer Off
    
    ''' <summary>
    ''' One thing to remember about a SaveFileDialog and an OpenFileDialog 
    ''' is that neither of them do what their name suggests! They each allow 
    ''' the developer to show the user a way to select a file path, but they 
    ''' don't "open" or "save" anything; that's up to your code to do.
    ''' </summary>
    ''' <remarks></remarks>
    Public NotInheritable Class CommonFileDialogs
        ''' <summary>
        ''' A shared method which will return the file path that the user 
        ''' has selected. Be sure to test whether or not the return value 
        ''' is null.
        ''' </summary>
        ''' <param name="initialDirectory">The initial directory that this dialog 
        ''' should use.</param>
        ''' <param name="filter">OPTIONAL: A string set up for the file filter. 
        ''' Default: Null.</param>
        ''' <param name="defaultExtension">OPTIONAL: A string which will become 
        ''' the default file extension. Be sure to NOT include the dot. Default: 
        ''' Null.</param>
        ''' <param name="title">OPTIONAL: A title to present to the user. Default: 
        ''' Null.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function _
            SaveFileDialog(ByVal initialDirectory As String, _
                           Optional ByVal filter As String = Nothing, _
                           Optional ByVal defaultExtension As String = Nothing, _
                           Optional ByVal title As String = Nothing) As String
    
            Dim retVal As String = Nothing
    
            If Not String.IsNullOrWhiteSpace(initialDirectory) Then
                Dim di As New IO.DirectoryInfo(initialDirectory)
    
                If di.Exists Then
                    Using sfd As New SaveFileDialog
                        With sfd
                            .InitialDirectory = di.FullName
    
                            If Not String.IsNullOrWhiteSpace(filter) Then
                                .Filter = filter.Trim
                                .FilterIndex = 1
                            End If
    
                            If Not String.IsNullOrWhiteSpace(defaultExtension) Then
                                .AddExtension = True
                                .DefaultExt = defaultExtension.Trim
                            End If
    
                            If Not String.IsNullOrWhiteSpace(title) Then
                                .Title = title.Trim
                            End If
    
                            .CheckFileExists = True
                            .CheckPathExists = True
                        End With
    
                        If sfd.ShowDialog = DialogResult.OK Then
                            retVal = sfd.FileName
                        End If
                    End Using
                End If
            End If
    
            Return retVal
    
        End Function
    
        ''' <summary>
        ''' A shared method which will return the file path that the user selected. 
        ''' Be sure to test whether or not the return value is null.
        ''' </summary>
        ''' <param name="initialDirectory">The initial directory that this dialog 
        ''' should use.</param>
        ''' <param name="filter">OPTIONAL: A string set up for the file filter. 
        ''' Default: Null.</param>
        ''' <param name="title">OPTIONAL: A title to present to the user. Default: 
        ''' Null.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function _
            OpenFileDialog_SingleFileSelect(ByVal initialDirectory As String, _
                                            Optional ByVal filter As String = Nothing, _
                                            Optional ByVal title As String = Nothing) As String
    
            Dim retVal As String = Nothing
    
            If Not String.IsNullOrWhiteSpace(initialDirectory) Then
                Dim di As New IO.DirectoryInfo(initialDirectory)
    
                If di.Exists Then
                    Using ofd As New OpenFileDialog
                        With ofd
                            .Multiselect = False
                            .InitialDirectory = di.FullName
    
                            If Not String.IsNullOrWhiteSpace(filter) Then
                                .Filter = filter.Trim
                                .FilterIndex = 1
                            End If
    
                            If Not String.IsNullOrWhiteSpace(title) Then
                                .Title = title.Trim
                            End If
                        End With
    
                        If ofd.ShowDialog = DialogResult.OK Then
                            retVal = ofd.FileName
                        End If
                    End Using
                End If
            End If
    
            Return retVal
    
        End Function
    
        ''' <summary>
        ''' A shared method which will return the file paths (as a string array) that 
        ''' the user selected. Be sure to test whether or not the return value is null.
        ''' </summary>
        ''' <param name="initialDirectory">The initial directory that this dialog 
        ''' should use.</param>
        ''' <param name="filter">OPTIONAL: A string set up for the file filter. 
        ''' Default: Null.</param>
        ''' <param name="title">OPTIONAL: A title to present to the user. Default: 
        ''' Null.</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function _
            OpenFileDialog_MultiFileSelect(ByVal initialDirectory As String, _
                                           Optional ByVal filter As String = Nothing, _
                                           Optional ByVal title As String = Nothing) As String()
    
            Dim retVal As String() = Nothing
    
            If Not String.IsNullOrWhiteSpace(initialDirectory) Then
                Dim di As New IO.DirectoryInfo(initialDirectory)
    
                If di.Exists Then
                    Using ofd As New OpenFileDialog
                        With ofd
                            .Multiselect = True
                            .InitialDirectory = di.FullName
    
                            If Not String.IsNullOrWhiteSpace(filter) Then
                                .Filter = filter.Trim
                                .FilterIndex = 1
                            End If
    
                            If Not String.IsNullOrWhiteSpace(title) Then
                                .Title = title.Trim
                            End If
                        End With
    
                        If ofd.ShowDialog = DialogResult.OK Then
                            retVal = ofd.FileNames
                        End If
                    End Using
                End If
            End If
    
            Return retVal
    
        End Function
    End Class

    Example Usage:

    Option Strict On Option Explicit On Option Infer Off Public Class Form1 Private Sub Form1_Load(sender As System.Object, _ e As System.EventArgs) _ Handles MyBase.Load ' My suggestion is to add a class to your project ' which has shared methods. If you're not sure ' how, it's as simple as right-clicking in ' Solution Explorer and choosing "Add" >> "Class". ' ' The name of my class is "CommonFileDialogs" and ' I'll show the code in the forum. ' ' The following shows how you might use this from ' any form in your project: ShowExample() Stop End Sub Private Sub ShowExample() Dim myDocuments As String = _ Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) If CommonFileDialogs.SaveFileDialog(myDocuments) IsNot Nothing Then Stop End If End Sub End Class



    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Wednesday, May 24, 2017 11:15 PM ...forgot to include the screenshot
    • Marked as answer by dw80916 Wednesday, July 5, 2017 10:03 PM
    Wednesday, May 24, 2017 11:07 PM