473,327 Members | 2,007 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,327 software developers and data experts.

Application.Exit() 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.Directory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.Directory) '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", MessageBoxButtons.YesNo)

If Result = DialogResult.Yes Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Visible = False

'Close up.

Me.Close()

Application.Exit()

End If

End If

End Sub
Nov 21 '05 #1
3 1502
Are you calling your Check_For_Dir() Sub from within the Sub New by any
chance? If so, Application.Exit won't work.
"Mike Johnson" <jo*****@bellsouth.net> wrote in message
news:O9**************@TK2MSFTNGP11.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.Directory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.Directory) '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", MessageBoxButtons.YesNo)

If Result = DialogResult.Yes Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Visible = False

'Close up.

Me.Close()

Application.Exit()

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", _
MessageBoxButtons.YesNo) = DialogResult.Yes 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.Directory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.Directory) '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", MessageBoxButtons.YesNo)

If Result = DialogResult.Yes Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Visible = False

'Close up.

Me.Close()

Application.Exit()

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.Exit.

--
Jonathan Allen
"Mike Johnson" <jo*****@bellsouth.net> wrote in message
news:O9**************@TK2MSFTNGP11.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.Directory) ' Retrieve the first entry.

Do While Count <> 10000

If MyName = "" Then ' Start the loop.

Count = Count + 1

MyName = Dir(MyPath, FileAttribute.Directory) '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", MessageBoxButtons.YesNo)

If Result = DialogResult.Yes Then

'Run Sub again

Check_For_Dir()

Else

'Hide the tray icon.

'NotifyIcon.Visible = False

'Close up.

Me.Close()

Application.Exit()

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
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). ...
4
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...
6
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...
12
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...
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...
4
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...
4
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...
5
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...
3
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...
7
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.