-
August 4th, 2004, 09:13 PM
#1
Unload Form does not always terminate program execution
I've seen several cases where all of the forms in my app are closed, yet dialog boxes still pop up, indicating a problem.
This makes the users feel uneasy :-)
What is the proper way to COMPLETELY terminate execution in a VB app, after all the forms have been unloaded ?
-
August 4th, 2004, 10:13 PM
#2
Just make sure that after you have unloaded the form there shoud be no code in the program that makes use of the form.
Busy
-
August 4th, 2004, 10:59 PM
#3
I agree with Thread1. If there is a need for a form to call an object in another form, programmer must explicitly define a way so that the calling form first check if the owner of the object to be called is loaded or not.
I am inviting you to join GreenZap. It is just like PAYPAL but it is more rewarding! You get $25 when you join (FREE to sign up) AND you get rewarded also when someone opened an account using your GreenZap promo code! GreenZap is launching June 1st.
Click here and PREREGISTER
Have a break. Visit JonelsPlace
-
August 5th, 2004, 12:15 AM
#4
Oddly enough, I've seen cases where a simple single-form program won't completely unload on a system running winME, but on other OS's it's ok. I used End as the last line of code after the form unloads, which seems to have solved the problem.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
August 5th, 2004, 03:23 AM
#5
Well...are you sure that all forms are unloaded...? You can check it within the 'Query_Unload' evetn of the main dialog...add the following
Code:
Dim FormX as Form
For Each FormX in Forms
if FormX.hWnd<> Me.hWnd then
Debug.Print "Form is still loaded"
Unload FormX
End If
Next
-
August 5th, 2004, 08:03 AM
#6
Avoid End command
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 5th, 2004, 09:15 AM
#7
Cimperiali
Yes, I know that using End isn't supposed to be good, but when you do a test like the following and the program stays in memory (seen in task manager), what then?
Code:
'absolutely no code whatsoever. just a blank form.
'No objects of any kind. No controls either.
A totally blank form compiled into an exe stays running on winME only.
So, I tried "Unload Me" and of course that didn't work. Using End in the Form_Unload sub did the trick. Sure it just terminates the program, but if it's used AFTER everything has been handled the right way anyway, then I would think it wouldn't be so bad.
Basically, I did it this way:
Code:
Private Sub Form_Unload(Cancel As Integer)
'set all objects to nothing
'unload any forms still loaded
End
End Sub
Since the form is unloading at this point anyway, what's left but to terminate?
If there's a better way to do it I'd sure like to know, as I didn't want to use End either.
Please remember to rate the posts and threads that you find useful.
How can something be both new and improved at the same time?
-
August 5th, 2004, 09:51 AM
#8
I have alwasy been a major opponent of using the END statement. However, I will have to agree with WizBang on this one. The program I wrote for our company had nothing but problems on Windows ME. Out of memory errors, stack overflow, and just plain not ending properly. Things worked fine on all our 98/2000 systems. For us it was an easy decision to spend the money and upgrade to 2000. Unfortunately, this can't always be done. My suggestion is that in your VB apps, you state that will run on 98/200/XP. Leave ME out of it. But if you have to put your app on ME. please, by all means use the END.
-
August 5th, 2004, 09:52 AM
#9
Why not get the form's address and free it?
James
james
-
August 5th, 2004, 12:42 PM
#10
Originally Posted by jamesa
Why not get the form's address and free it?
James
And how is that done ?
-
August 5th, 2004, 12:46 PM
#11
and avoid "End" (unless on a very bugged Os...)
Since VB only runs on Windows, all of those OS's are very buggy.
W98 is one of the worst of the lot.
-
August 5th, 2004, 12:57 PM
#12
Thanks for all the great answers- it looks like End should not be used.
One of The problems with the program I am maintaining is
it has about 10 forms, and the person who wrote it iriginally, never checked for errors during executuion.
This program triggers an oscilloscope through GPIB, and if the scope probe isn't connected securely to a test point, the scope wont trigger. But the code which calls the triggering code, calls it many times.
When the scope doesn't trigger, the users typically exit the program, and restart it. When the user selects Exit from any of the Form Menus this code gets called (which is in a .BAS file)
Sub ProgramEnd(CallingWindowHandle As Long)
Dim Form As Form
' ProgramIsUnloading MUST be set here, or the forms wont be unloaded
ProgramIsUnloading = True
For Each Form In Forms
If Form.hwnd <> CallingWindowHandle Then
Unload Form
End If
Next
end sub
However, even though all of the forms are closed, the code trying to trigger the scope is still running, as verified by task manager.
So when the user runs a second instance of the program ( the old instance is running, but not visible) both programs try to talk to the scope, which results in both programs hanging.
I want to re-write the scope triggering code, so an error is returned, when the scope doens't trigger. However, that's a lot of code, so I was hoping for a quicker fix (like End, or something).
-
August 5th, 2004, 01:21 PM
#13
Did you stop timers and exit all loops?
Btw, Wizbang: "unless on buggy Os" =that was exactly for Windows Me,
a horrible one that I remember only for bugs...
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
August 5th, 2004, 02:43 PM
#14
ExitProcess seems to be a good way to end a program too, see this thread:
http://www.codeguru.com/forum/showthread.php?t=206561
I think everyone remember Windows ME as a really buggy os...
JeffB
-
August 5th, 2004, 03:50 PM
#15
Triggering / de-triggering the code !
It seems like the original coder failed to apply any " Exit Do " statement's
within your Looping structure's
Apply : " Exit Do " ' in your Loop's < This should basically be your pivot point ,
Code:
If Button = 1 then
Exit Do
End If
Apply : " Do Events "' Between your Loop's < this will allow Windows to destroy
' Your program during the Unload Event
The use of " End " in the Unload Event just forces Windows to crash exit the application , leading to an internally messy destroy .
If there is any Blitting then more than likely the original coder failed to include the necessary " Destroy DC " , in which case Windows is still trying to write into memory .
Really just guessing here , don't really know what the structure is.....
How can anyone sell information when all the information that they sell is free at the library ?
How come Doctors keep getting smarter yet they cannot cure the common cold ?
If Scientist are right and man evolved from monkey then where did the monkeys' come from ?
Man I love this little dude that waves => <= He just doesn't stop
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
|