473,883 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Exi t() problem

I have the following code in form1 and when the application starts this sub
is called to check for a path if not found a message box is displayed and
then gives the user an option to end the application but when this option is
selected the application does not end but continues to the next line of code
which tries to setup a filewatcher with the path which does not exist, which
then gives an error. please help.

Public Sub Check_For_Dir()

Dim MyPath, MyName As String

Dim Count As Integer

Dim Result As DialogResult

Count = 0

MyPath = FilePath ' Set the path.

MyName = Dir(MyPath, FileAttribute.D irectory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.D irectory) 'Check again

Else

Exit Do

End If

Loop

If Count = 10000 Then

'Displays Message

Result = MessageBox.Show ("Path " + FilePath + " not available, press Yes to
try again or No to Exit.", "Error", MessageBoxButto ns.YesNo)

If Result = DialogResult.Ye s Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Vis ible = False

'Close up.

Me.Close()

Application.Exi t()

End If

End If

End Sub
Nov 21 '05 #1
3 1575
Are you calling your Check_For_Dir() Sub from within the Sub New by any
chance? If so, Application.Exi t won't work.
"Mike Johnson" <jo*****@bellso uth.net> wrote in message
news:O9******** ******@TK2MSFTN GP11.phx.gbl...
I have the following code in form1 and when the application starts this sub
is called to check for a path if not found a message box is displayed and
then gives the user an option to end the application but when this option
is
selected the application does not end but continues to the next line of
code
which tries to setup a filewatcher with the path which does not exist,
which
then gives an error. please help.

Public Sub Check_For_Dir()

Dim MyPath, MyName As String

Dim Count As Integer

Dim Result As DialogResult

Count = 0

MyPath = FilePath ' Set the path.

MyName = Dir(MyPath, FileAttribute.D irectory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.D irectory) 'Check again

Else

Exit Do

End If

Loop

If Count = 10000 Then

'Displays Message

Result = MessageBox.Show ("Path " + FilePath + " not available, press Yes
to
try again or No to Exit.", "Error", MessageBoxButto ns.YesNo)

If Result = DialogResult.Ye s Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Vis ible = False

'Close up.

Me.Close()

Application.Exi t()

End If

End If

End Sub

Nov 21 '05 #2
Mike,

I changed your code a little in this snippet bellow, your code looks a
little bit outdated with declaring all variables in top and than using the
do while where an for index is very simple to use.

\\\
For i As Integer = 0 To 9999
If MessageBox.Show ("Path", "Error", _
MessageBoxButto ns.YesNo) = DialogResult.Ye s Then
'do your stuff
Else
Me.Close()
Exit Sub
End If
Next
///

(As extra advice, paste next time your code in a notebook first and copy it
back and then into the message will give you probably more answers, than it
will be more readable, now it is difficult to get a quick overview)

I hope this helps?

Cor

"Mike Johnson"
I have the following code in form1 and when the application starts this sub
is called to check for a path if not found a message box is displayed and
then gives the user an option to end the application but when this option
is
selected the application does not end but continues to the next line of
code
which tries to setup a filewatcher with the path which does not exist,
which
then gives an error. please help.

Public Sub Check_For_Dir()

Dim MyPath, MyName As String

Dim Count As Integer

Dim Result As DialogResult

Count = 0

MyPath = FilePath ' Set the path.

MyName = Dir(MyPath, FileAttribute.D irectory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.D irectory) 'Check again

Else

Exit Do

End If

Loop

If Count = 10000 Then

'Displays Message

Result = MessageBox.Show ("Path " + FilePath + " not available, press Yes
to
try again or No to Exit.", "Error", MessageBoxButto ns.YesNo)

If Result = DialogResult.Ye s Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Vis ible = False

'Close up.

Me.Close()

Application.Exi t()

End If

End If

End Sub

Nov 21 '05 #3
1. Use a sub main that calls Application.Run if you find all your files.
This avoids the need to use Applciation.Exi t.

--
Jonathan Allen
"Mike Johnson" <jo*****@bellso uth.net> wrote in message
news:O9******** ******@TK2MSFTN GP11.phx.gbl...
I have the following code in form1 and when the application starts this sub is called to check for a path if not found a message box is displayed and
then gives the user an option to end the application but when this option is selected the application does not end but continues to the next line of code which tries to setup a filewatcher with the path which does not exist, which then gives an error. please help.

Public Sub Check_For_Dir()

Dim MyPath, MyName As String

Dim Count As Integer

Dim Result As DialogResult

Count = 0

MyPath = FilePath ' Set the path.

MyName = Dir(MyPath, FileAttribute.D irectory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.D irectory) 'Check again

Else

Exit Do

End If

Loop

If Count = 10000 Then

'Displays Message

Result = MessageBox.Show ("Path " + FilePath + " not available, press Yes to try again or No to Exit.", "Error", MessageBoxButto ns.YesNo)

If Result = DialogResult.Ye s Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Vis ible = False

'Close up.

Me.Close()

Application.Exi t()

End If

End If

End Sub

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
17723
by: Brendan Miller | last post by:
I am trying to close my application using Application.exit() in the frmMain_Closing event. When the form closes the process does not. My application only has one form (no other classes either). The form has a really long loop which generates approx. 700 .csv files. I do not create any threads myself (Application.exitthread() doesn't work either). To counteract this I have decided to use the Environment.exit(-1) method instead. What...
4
11177
by: Chuck | last post by:
Hello everybody, I need to abort execution during start up, while the constructor called by Application.Run is executing. If the database fails to connect during my application's startup I want to display a message (no problem here) and then abort the program. However, after the attached code executes I end up with my main form and a wait cursor! If I click on the X the form closes. Boss doesn't think an unhandled exception will...
6
20097
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are quite a few words in this post but the questions are actually quite similar and should be fairly quick to answer ... (1) What is Happening with the Threads
12
5889
by: JohnR | last post by:
I have narrowed a problem down to a simple example. A form with two buttons. One EXIT and one FBD. The exit button does an "END" to end the application. The FBD button does a FolderBrowserDialog and nothing else. When I start the application and hit EXIT everything works fine. However if it display the FBD box (even if I don't pick a folder and immediately hit cancel) and then try to exit one of two things happens. Either (1) the...
20
2729
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...
4
4128
by: vul | last post by:
I start the application with Application.Run(New MDIMain) in Sub Main. MDIMain is the mdi form which loads and then calls Login form. I'm using Application.Exit to terminate my VB 2005 application on Login screen if user clicks on Cancel button. When I do this I get a sound as MessageBox produces. I do not see any messages, but VB environment works abnormally after that. It doesn't switch modules until I minimize it and maximize again or...
4
3416
by: Markus Stoeger | last post by:
Hi, I have a problem with Application.Run() when Windows is shutting down. Please have a look at the copy&paste example program below. The application has no forms. It has only got a notify icon in the system tray and it uses Application.Run() to keep the message loop running. When the user clicks the icon, the application should shut down and exit. So far that works fine.
5
2611
by: Patrick F | last post by:
I have a problem closing down the application, i haven't dont much in the project yet, so it contains a program.cs file (generated by Visual studio) with the main function. Also my main form, now my problem is that, in afew places in my mainForm i want to Exit the application and close the probram, when i try: Application.Exit(); nothing happens, it keeps running. Then i also tried to add private void mainForm_FormClosed(object sender,...
3
2064
by: Marcel Saucier | last post by:
I have written a Console Application then created a shortcut to it on my desktop. I was able to minimize the DOS window when I click my shortcut so I dont see anymore the DOS window But, using Task Manager to run the shortcut, I am not able to get rid of (minimize) the DOS window. Is there somebody that is aware of this problem ? My application is an agenda, so Task Manager runs it every 15 minutes, to
7
4320
by: Jay | last post by:
In my C# code, I'm attempting to display a message box then quit the win form application I'm writing if a certain type of error occurs when the application starts up. In the main form's constructor - FormMain() - if this error occurs, I display a message box then call Application.Exit(). The problem is that I also need to have some code in my FormMain_FormClosing event handler, but this prevents Application.Exit() from quitting the...
0
9944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9793
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
10420
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9582
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7134
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
5804
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...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4619
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
3238
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.