Handling Cancels in Directory Dialog
Handling Cancels in Directory Dialog
(OP)
I have tried this in two different ways.
As well as
The first has no reaction when the cancel button is used and the second hits the error regardless of whether the cancel button is hit or not.
Any help with this would be greatly appreciated.
CODE
Try
Dim dialog As new FolderBrowserDialog()
dialog.description = "Select Directory containing loft data."
strDir = dialog.ShowDialog()
strDir = dialog.SelectedPath
Catch E As Exception
MessageBox.Show("Program cannot continue without lofting data location.", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
Dim dialog As new FolderBrowserDialog()
dialog.description = "Select Directory containing loft data."
strDir = dialog.ShowDialog()
strDir = dialog.SelectedPath
Catch E As Exception
MessageBox.Show("Program cannot continue without lofting data location.", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
As well as
CODE
Dim dialog As new FolderBrowserDialog()
dialog.description = "Select Directory containing loft data."
strDir = dialog.ShowDialog()
strDir = dialog.SelectedPath
On Error GoTo DirCanceledError
.
.
.
DirCanceledError:
'------------------------------------------------------------------------------------------
' If the user cancels the Directory Form, Exit the program
'------------------------------------------------------------------------------------------
MessageBox.Show("Program cannot continue without lofting data location.", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
dialog.description = "Select Directory containing loft data."
strDir = dialog.ShowDialog()
strDir = dialog.SelectedPath
On Error GoTo DirCanceledError
.
.
.
DirCanceledError:
'------------------------------------------------------------------------------------------
' If the user cancels the Directory Form, Exit the program
'------------------------------------------------------------------------------------------
MessageBox.Show("Program cannot continue without lofting data location.", "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
The first has no reaction when the cancel button is used and the second hits the error regardless of whether the cancel button is hit or not.
Any help with this would be greatly appreciated.





RE: Handling Cancels in Directory Dialog
CODE
' Then use the following code to create the Dialog window
' Change the .SelectedPath property to the default location
With FolderBrowserDialog1
' Desktop is the root folder in the dialog.
.RootFolder = Environment.SpecialFolder.Desktop
' Select the C:\ directory on entry.
.SelectedPath = "C:\"
' Prompt the user with a custom message.
.Description = "Select the directory to export .dxf file(s)"
If .ShowDialog = DialogResult.OK Then
strOutputFolder = .SelectedPath
else
exit sub
End If
End With
www.nxjournaling.com