473,839 Members | 1,410 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Exi t() 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.Exi t() 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.D irectory) ' 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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
'Run Sub again
Check_For_Dir()
Else
Me.Close()
Exit Sub
End If
Next
End Sub
Nov 21 '05 #1
2 1367
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(ByVa l sender As Object, ByVal e As System.EventArg s)
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.D irectory) ' 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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
'Run Sub again
Check_For_Dir()
Else
Application.Exi t
Exit Sub
End If
Next

End Sub


"Mike Johnson" <jo*****@bellso uth.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
The sub is being called from the Sub New(). If I can't use
Application.Exi t() 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.D irectory) ' 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", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
'Run Sub again
Check_For_Dir()
Else
Me.Close()
Exit Sub
End If
Next
End Sub

Nov 21 '05 #2
"Mike Johnson" <jo*****@bellso uth.net> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
The sub is being called from the Sub New(). If I can't use
Application.Exi t() 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
2525
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 user wants to save the data, but when the Application closes this event isn't thrown automatically. I added a loop to close each child window, but can't seem find how to catch the child window's cancel of the Closing event, so even if the user...
7
5969
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, in this instance, the program gets a segmentation fault on exit. I already posted this question, but people were asking for some code, so here it is: #define DWORD unsigned long
63
3153
by: Aaron Ackerman | last post by:
What is the sytax for exiting a for loop in C#?
2
2904
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 mandatory, therefore if the setting is not present the application should exit. I know I could throw an exception to the main program, or even return nothing, make a check wich will close the application if its Nothing. But this means more code on the...
20
2727
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 contrast to one of them always being 'modal' (e.g., if you are moving over a picture the 'Info' form will update the (x,y) screen location in realtime even if not the selected form. Also note that this example implies the various forms can communicate...
10
2269
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 exit. i passed the boolean true parameter to the Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean), it does not do anything... i've included a finalize procedure with no codes but still no go.
22
3253
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 in under a second but it rises to about one minute under duress. The code is fairly straight forward with no calls to databases or any other servers. The only dubious thing I can see is that it retrieves several arrays from the Application...
17
3557
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 populated when a user scans a label. The other is ScanDate - a date/time field that should equal the date/time of the scan (e.g. 7/31/2006 5:00:00 AM).
13
6919
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 frm Garry
0
9698
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10914
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10597
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10656
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7834
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5684
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.