By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Application.Exit() problem post number #2 I've made the correction suggested.

P: n/a
The sub is being called from the Sub New(). If I can't use
Application.Exit() in this situation then how do I exit the application?
please help.

Public Sub Check_For_Dir()
Dim MyPath, MyName As String
MyPath = FilePath ' Set the path.
MyName = Dir(MyPath, FileAttribute.Directory) ' Retrieve the first
entry.
For i As Integer = 0 To 9999
If MessageBox.Show("Path " + FilePath + " not available, press
Yes to try again or No to Exit.", "Error", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
'Run Sub again
Check_For_Dir()
Else
Me.Close()
Exit Sub
End If
Next
End Sub
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Set Form Visible = False then put Check_For_Dir() in then Form Load event.
If everything is OK the set Visible = True.

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Check_For_Dir()
Me.Visible = True
End Sub
Public Sub Check_For_Dir()
Dim MyPath, MyName As String
MyPath = FilePath ' Set the path.
MyName = Dir(MyPath, FileAttribute.Directory) ' Retrieve the first
entry.
For i As Integer = 0 To 9999
If MessageBox.Show("Path " + FilePath + " not available, press
Yes to try again or No to Exit.", "Error", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
'Run Sub again
Check_For_Dir()
Else
Application.Exit
Exit Sub
End If
Next

End Sub


"Mike Johnson" <jo*****@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The sub is being called from the Sub New(). If I can't use
Application.Exit() in this situation then how do I exit the application?
please help.

Public Sub Check_For_Dir()
Dim MyPath, MyName As String
MyPath = FilePath ' Set the path.
MyName = Dir(MyPath, FileAttribute.Directory) ' Retrieve the first
entry.
For i As Integer = 0 To 9999
If MessageBox.Show("Path " + FilePath + " not available, press
Yes to try again or No to Exit.", "Error", _
MessageBoxButtons.YesNo) = DialogResult.Yes Then
'Run Sub again
Check_For_Dir()
Else
Me.Close()
Exit Sub
End If
Next
End Sub

Nov 21 '05 #2

P: n/a
"Mike Johnson" <jo*****@bellsouth.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
The sub is being called from the Sub New(). If I can't use
Application.Exit() in this situation then how do I exit the application?
please help.


Throw an Exception.
This will give you a nasty run-time error dialog rattling on about
an unhandled exception - no surprise, there; you just threw one!

To make this a little cleaner, start you program from Sub Main
(needs a little bit more code to get the Form's message loop up
and running), but you can catch the Exception, ignore it and let the
program quietly die, as in

Sub Main
Try
' Run the application's main form.
Application.Run(New Form1())

Catch ex as Exception
' Do Nothing
' - Or, maybe, give the User a nicer error

End Try

' Reaching here ends the program.
End Sub

HTH,
Phill W.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.