473,382 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

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
2 1331
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window catches its Closing event and cancels it if the...
7
by: James Leddy | last post by:
For some reason, I get a segmentation fault when I exit this program I made. Most of the time when I have seen this it has occured in the middle of the program and the program terminates. However,...
63
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
2
by: Juan Pedro Gonzalez | last post by:
Helo, My question is how can I exit an application from a class Library... I've got a class library wich I use to load and save user setting for my application, some of this settings are...
20
by: Peter Oliphant | last post by:
How does one launch multiple forms in an application? Using Photoshop as an example, this application seems to be composed of many 'disjoint' forms. Yet, they all seem somewhat 'active' in...
10
by: Ronin | last post by:
Group, i hope someone is able to help with this issue. I'd like the form to exit after certain logic calculation... i tried the me.dispose with in the Sub New() procedure, but it does not...
22
by: roadrunner | last post by:
Hi, Our website has recently been experiencing some problems under load. We have pinpointed a particular function which slows dramatically when we have these problems. Normally it should execute...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
13
by: Garry | last post by:
Why is it that my installation od vs2005 will not accept My.Application.OpenForms saying that it is not part of My.Application??? Dim frm As Form For Each frm In My.Application.OpenForms Next...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.