Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

VS 2010 [RESOLVED] Open File Dialogue Cancel Button not returning expected message

$
0
0
I can't seem to figure out why this code is not returning a message when the cancel button is clicked. :confused::confused: I get "OpenFileDialog1"

Code:


    Private Sub mnuOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpen.Click
     

        Dim strFileName As String
        Dim CancelButtonClicked As Integer

        OpenFD.InitialDirectory = "c:\"
        OpenFD.Title = "Open a File"
        OpenFD.Filter = "Text File|*.txt|Word Files|*.doc"       
        OpenFD.ShowDialog() 'shows a list of the files that can be opened in the Int. Directory

        'Test if Cancel Button is clicked
        If CancelButtonClicked = Windows.Forms.DialogResult.Cancel Then
            MessageBox.Show("Cancel Button Clicked")
        Else
            strFileName = OpenFD.FileName 'Variable holds the value of the file name selected
            MessageBox.Show(strFileName) 'Display file name on the screen in a messagebox
        End If

    End Sub


Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>