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