×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Handling Cancels in Directory Dialog

Handling Cancels in Directory Dialog

Handling Cancels in Directory Dialog

(OP)
I have tried this in two different ways.

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

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

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

Check the dialog result and do something based on it. The example below simply exits if cancel is pressed.

CODE

Dim FolderBrowserDialog1 As New FolderBrowserDialog

' 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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close