Solved

Starting app threw Sub Main

Posted on 1998-07-15
12
355 Views
Last Modified: 2010-05-03
Never used it before,
but lately, I have seen the light, on its little advantage.

Then again, How do you stop your application from running,
I used to simply unload all the forms... that doesn't work anymore.
I hate to use End, and I would prefer not too...

My question, how do you stop the application, without using End,
when you have started it threw Sub Main?
0
Comment
Question by:shannon_cogan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 6

Expert Comment

by:clifABB
ID: 1465795
You *should* use End.  
End is a good thing.  
Place the end command in the Unload or QueryUnload event of your main form.
0
 
LVL 1

Expert Comment

by:wford
ID: 1465796
Is your sub main still running, Even when all the forms are unloaded?

If so, then all you need to do is put an "exit sub" in the sub main, and if all the forms are unloaded, then your app should stop too.


0
 
LVL 1

Expert Comment

by:Anita030598
ID: 1465797
I wouldn't suggest using End statement anywhere. As wford mentioned it exiting the main sub will stop your app if all the forms are unloaded. However, if you have created any objects for global use by referring to any DLL or out any class module in the project, you will have to clear all those objects by setting them to Nothing.

When your App is not terminating as expected, this is the main point I would look for. I wouldn't definitely use End statement.

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:clifABB
ID: 1465798
I must again make my point for using the End statement.

It is good programming practice to always put a definite ending point in your application.  Especially in an event driven language such as VB.  If you were to enter Sub Main() without loading any forms, call a subroutine which contains a DoEvents and that subroutine goes into an endless loop, The end of Sub Main will occur.  However, just exiting Sub Main() won't stop the application in this case.  Given time, I could name other instances which would have the same (or similar) results.

As far as Anita's statement that if you use End you will have to set objects to nothing, it is also good programming practice to do this anyway.  Whether it's database objects, OLE objects, Device Contexts, or whatever, the rules always say:
"If you use it, put it away when you're done with it."
0
 
LVL 1

Expert Comment

by:Anita030598
ID: 1465799
Just to clarify clifABB, I did not state that if you use End you will have to set the objects to Nothing. I did not mean it that way. Yes, you are right that you have to clear them always.

What I said is, in general, you need to clear any objetcs if you have created. It has nothing to do with the End statement. I have seen many times, people would have created some objects for Global use, would have the reference to some objects in some DLL but never bother to clear them by setting them to Nothing. This does causes the App and DLLs to be still in memory. Then they wouldn't know what's happening and they go and put End statement. That helps some times. But that's not the right way to do.

Generally, when all the Forms are unloaded and all the objects are cleared the App will go away without having an End statement anywhere in the Program. Of course, if you have some endless loops, then we are talking completely different issues.
0
 
LVL 1

Expert Comment

by:Anita030598
ID: 1465800
Just to clarify clifABB, I did not state that if you use End you will have to set the objects to Nothing. I did not mean it that way. Yes, you are right that you have to clear them always.

What I said is, in general, you need to clear any objetcs if you have created. It has nothing to do with the End statement. I have seen many times, people would have created some objects for Global use, would have the reference to some objects in some DLL but never bother to clear them by setting them to Nothing. This does causes the App and DLLs to be still in memory. Then they wouldn't know what's happening and they go and put End statement. That helps some times. But that's not the right way to do.

Generally, when all the Forms are unloaded and all the objects are cleared the App will go away without having an End statement anywhere in the Program. Of course, if you have some endless loops, then we are talking completely different issues.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1465801
Anita:
My apologies, I misread what you said.
On my point, I was saying that if you put an End statement, you have a definite ending point.  While and End won't always remove objects, it will stop the application including endless loops, timers, etc.
0
 

Expert Comment

by:idcvbteam
ID: 1465802
funny, putting an end statement cause my app to crash!
It raises an error 10H in the msvb5*.dll

0
 
LVL 6

Expert Comment

by:alamo
ID: 1465803
End is a good safety, except that if it is needed then often something is wrong. At the very least I leave it out during development.

An old version of VB (1.0 maybe?) had a bug (relating to VBXs IIRC) where End would reliably corrupt memory. As a result I got in the habit of not using End. Today it's probably safe but I still shy away out of habit.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1465804
I have rethought my stand on End.
Here is a portion from VB's help file in reference to the End statement:
"The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing."

As I am not the first (nor the second) to point out that unloading all forms will terminate an app, I will not submit this as an answer (that honour should go to wford).  
I'm just pointing out that I have been convinced.  :)
0
 
LVL 1

Accepted Solution

by:
wford earned 20 total points
ID: 1465805
Thanks ClifABB
If shannon wants to accept, I will be happy to take the points, but I would like to know if that was, in fact the problem?
0
 

Author Comment

by:shannon_cogan
ID: 1465806
I will accept wford, as this seems to be the problem.
You all had me scared, such good points for yourselves.
Anita, thank you too... as to pin point the problem, Dlls were still in use.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question