I have run into a problem that seems fairly simple, but my program is not working the way I want it to. I am opening a file dialog, and when I press cancel, the file dialog will open and again..I press cancel and then it shows the message box(You have pressed cancel). Again I open the file dialog and when I select the file and press OK, the file dialog box opens yet again, I have to select the file again and then it displays the filepath in the text box and the message box accordingly. How can I get this down to be only one pass at both the cancel button and the file selection with the OK button. Please help asap. I have the code below.
Private Sub btnFileFind1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFileFind1.Click
Dim strFileName As String
Dim DidWork As Integer
'OpenFD.InitialDirectory = "C:\PRU401k"
OpenFD.Title = "Open a text file"
OpenFD.Filter = "Text Files(*.txt)|*******R.txt"
DidWork = OpenFD.ShowDialog()
If DidWork = DialogResult.Cancel Then
MsgBox("Cancel button clicked")
strFileName = OpenFD.FileName
TextBox1.Text = strFileName