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

Me.close vs. End

cj
What is the difference between using Me.close vs. End to stop the
execution of a program?

I've been using me.close and putting code in the form.closing event to
make sure things are stopped before the program execution stops. This
has been working for me even when the startup is sub main perhaps
because my sub mail usually looks like

<STAThread()> Public Sub main(ByVal CmdArgs() As String)
Dim mainForm As New Form1
Application.Run(mainForm)
End Sub
May 31 '06 #1
6 11389

cj wrote:
What is the difference between using Me.close vs. End to stop the
execution of a program?
Even more so than in earlier incarnations of VB, you *should not use
End*. This is from the docs (my emphases):
The End statement stops code execution abruptly, **without invoking the
Dispose or Finalize method**, or any other Visual Basic code. Object
references held by other programs are invalidated. **If an End
statement is encountered within a Try or Catch block, control does not
pass to the corresponding Finally block.**
Because End terminates your application without attending to any
resources that might be open, **you should try to close down cleanly
before using **it. For example, **if your application has any forms
open, you should close them before control reaches the End statement.**

**You should use End sparingly, and only when you need to stop
immediately.** The normal ways to terminate a procedure (Return
Statement (Visual Basic) and Exit Statement (Visual Basic)) not only
close down the procedure cleanly but also give the calling code the
opportunity to close down cleanly. A console application, for example,
can simply Return from the Main procedure.

**Security Note
The End statement calls the Exit method of the Environment class in the
System namespace. Exit requires that you have UnmanagedCode permission.
If you do not, a SecurityException error occurs.**


I've been using me.close and putting code in the form.closing event to
make sure things are stopped before the program execution stops. This
has been working for me even when the startup is sub main perhaps
because my sub mail usually looks like

<STAThread()> Public Sub main(ByVal CmdArgs() As String)
Dim mainForm As New Form1
Application.Run(mainForm)
End Sub


What you are doing is the right way to do things.

--
Larry Lard
Replies to group please

May 31 '06 #2
cj,

Close is closing (let the program stop after all things done that are needed
for that)

End is killing (stop it at the place it is)

Cor

"cj" <cj@nospam.nospam> schreef in bericht
news:Oj**************@TK2MSFTNGP04.phx.gbl...
What is the difference between using Me.close vs. End to stop the
execution of a program?

I've been using me.close and putting code in the form.closing event to
make sure things are stopped before the program execution stops. This has
been working for me even when the startup is sub main perhaps because my
sub mail usually looks like

<STAThread()> Public Sub main(ByVal CmdArgs() As String)
Dim mainForm As New Form1
Application.Run(mainForm)
End Sub

May 31 '06 #3

Cor Ligthert [MVP] wrote:
cj,

Close is closing (let the program stop after all things done that are needed
for that)
But doesn't Close just close the current Form? And if the current form
is not the main form for the application, the closing that form will
not close the application. Don't you have to do a Close event in the
main form to close the application?

End is killing (stop it at the place it is)

Cor

"cj" <cj@nospam.nospam> schreef in bericht
news:Oj**************@TK2MSFTNGP04.phx.gbl...
What is the difference between using Me.close vs. End to stop the
execution of a program?

I've been using me.close and putting code in the form.closing event to
make sure things are stopped before the program execution stops. This has
been working for me even when the startup is sub main perhaps because my
sub mail usually looks like

<STAThread()> Public Sub main(ByVal CmdArgs() As String)
Dim mainForm As New Form1
Application.Run(mainForm)
End Sub


May 31 '06 #4
On 31 May 2006 12:47:19 -0700, za***@construction-imaging.com wrote:

Cor Ligthert [MVP] wrote:
cj,

Close is closing (let the program stop after all things done that are needed
for that)


But doesn't Close just close the current Form? And if the current form
is not the main form for the application, the closing that form will
not close the application. Don't you have to do a Close event in the
main form to close the application?


Have a look at the Application.Exit method

Gene
May 31 '06 #5
Zacks,.

If the mainform is the one that has its sub main in it (standard) than it
has instanced all its subforms as objects and therefore close those as
well.

If you use an seperated Sub Main have than a look at the message from Gene
about application exit.

Cor

<za***@construction-imaging.com> schreef in bericht
news:11**********************@u72g2000cwu.googlegr oups.com...

Cor Ligthert [MVP] wrote:
cj,

Close is closing (let the program stop after all things done that are
needed
for that)


But doesn't Close just close the current Form? And if the current form
is not the main form for the application, the closing that form will
not close the application. Don't you have to do a Close event in the
main form to close the application?

End is killing (stop it at the place it is)

Cor

"cj" <cj@nospam.nospam> schreef in bericht
news:Oj**************@TK2MSFTNGP04.phx.gbl...
> What is the difference between using Me.close vs. End to stop the
> execution of a program?
>
> I've been using me.close and putting code in the form.closing event to
> make sure things are stopped before the program execution stops. This
> has
> been working for me even when the startup is sub main perhaps because
> my
> sub mail usually looks like
>
> <STAThread()> Public Sub main(ByVal CmdArgs() As String)
> Dim mainForm As New Form1
> Application.Run(mainForm)
> End Sub

Jun 1 '06 #6
Hi,

Thank you for posting.

When Form.Close() is called, the form is closed and all resources created
within the object are closed and the form is disposed. The call of
Form.Close() invokes the Form.Closing and Form.Closed events. If the form
you are closing is the startup form of your application, your application
ends.

You can place the End statement anywhere in a procedure to force the entire
application to stop running. The End statement stops code execution
abruptly, without invoking the Dispose or Finalize method and the
Form.Closed or Form.Closing event. If an End statement is encountered
within a Try or Catch block, control does not pass to the corresponding
Finally block.If you have validation code in either of these events that
must be executed, you should call the Form.Close method for each open form
individually before calling the End statement.

Hope this is helpful to you.
If you have any other concerns or need anything else, please don't hesitate
to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

================================================== ==
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
================================================== ==

Jun 1 '06 #7

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

Similar topics

3
by: Daniel | last post by:
TcpClient close() method socket leak when i use TcpClient to open a connection, send data and close the TcpClient with myTcpClientInstance.Close(); it takes 60 seconds for the actual socket on...
6
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the...
10
by: Shang Wenbin | last post by:
Hi, When I want to close the current window using window.close() in IE6.0, there will be a confirm box that: The web page you are viewing is trying to close the window. Do you want to close this...
19
by: Lauren Wilson | last post by:
A2K app: Question: is the flagged line (<<<) below necessary. If that line is needed, what effect does it have (if any) on the fact that the very same database is the linked back end db? ...
4
by: GrantS | last post by:
I am having a problem closing a popup window opened modally. When I try to close the window (when the user hits save button and the data has been processed), the Popup window opens as a full screen...
35
by: Eric Sabine | last post by:
In my Finally block, I was using cn.close (where cn is an ADO.NET connection object, SQLConnection to be exact) and then I came across the following in some microsoft code. If Not cn Is Nothing...
8
by: Greg Strong | last post by:
Hello All, The short questions are 1 Do you know how to make DSN connection close in Access to Oracle 10g Express Edition? &/or 2 Do you know how to make a DSN-less pass-through query...
7
by: Toccoa | last post by:
After considerable googling - I mean searching with Google(r) - I could not find javascript on a button or <a href=... to close a window in the latest versions of IE and FireFox. There seemed...
2
by: kurt sune | last post by:
Hello, I have a weird problem, I hope someone can explain this for me. I have a webpage using masterpage. In it I create a popup window using this code: Dim js As String = "<script...
6
by: =?Utf-8?B?UGF1bA==?= | last post by:
I am looking for a java script to close a web form that I can attatch to a button click event. I am using vs2005, c#. Thanks -- Paul G Software engineer.
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: 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...
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
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...

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.