473,625 Members | 3,222 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 1543
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
17686
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
11153
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
20065
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
5861
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
2696
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
4109
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
3401
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
2600
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
2051
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
4308
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
8259
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
8192
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
8696
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
8637
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
8358
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,...
0
8502
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...
1
6119
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
5571
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();...
1
2621
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

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.