|
-
Mar 3rd, 2008, 06:06 PM
#5
Re: Classic VB - How should I close my form/program/class?
If it doesn't actually close, how can you find out why?
If you find that the program doesn't close when it is supposed to (if running in VB you need to press the "stop" button, or when compiled it is still listed in Task Manager), then you aren't unloading everything properly.
This may be because you have missed (or not correctly coded) one of the steps above, or because you have not unloaded items correctly in individual routines (or you have in the routine itself, but not in the error handler for it!).
Unfortunately it isn't always easy to find out what the cause of the problem is - you are going to have to check and/or debug your code, but hopefully these tips will reduce how much of it you need to check.
Finding which forms are still loaded
If your program has multiple forms, you can press the "pause" button in the IDE, and put code like this into the Immediate window (which you can see by going to "View" -> "Immediate"):
Code:
For Each f In Forms: MsgBox f.name: Next f
When you press Enter, this will tell you which forms are still open. While that doesn't give you the information you really want (which particular item or piece of code is causing the problem), at least it narrows down the possibilities.
Finding out if forms are being re-loaded
To find out when a form is loaded (or re-loaded, which can happen if you reference any of the properties (such as: Form1.Caption) after it has unloaded), you can add code like this to the Form_Load event of each form:
Code:
Debug.Print CStr(Time) & " loading form: " & Me.Name
This will print the time that each form is loaded to VB's Immediate window, and if the time shown is at/after the time you tried to unload, the form is being re-loaded by other code.
Tracking down the problem
If the above methods don't pinpoint the issue, you will need to Debug the code. To do this, put a breakpoint on the line of code where you start unloading (or better, the line that calls it) by pressing F9 on that line. Now run the program, and when it stops at that breakpoint, press F8 to run a single line of code at a time, and continue to do so until you find the problem. More information about debugging can be found in the tutorial Using VB6 Debug - Introduction
If after that you still can't find the problem, post a new thread in the Visual Basic 6 and Earlier forum, giving as much detail as you can.
.
Last edited by si_the_geek; Sep 23rd, 2009 at 07:42 AM.
Reason: added link to debug tutorial
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|