-
Completely closing out a form ...
VB6/WinXP/Hobby Programmer. I have traced several recent issues I've been having with my app to one problem in code. My app is waiting for input from the User in a loop, where I have several DoEvents statements (per suggestions here). I have discovered that when the User closes out of the App using the Close X on the form while this loop is running the form never gets out of the loop and hence never completely unloads (creating future problems).
When the user goes back to a directory form they can click on other choices then come back to this form as on option, which then loads another instance of this form while that first loop is still waiting for input (sometimes syncing up, but usually creating an eventual crash).
I realize I need additional code to clean up my exit from the form when the X is clicked (when the user leaves properly using a command button they are already outside of the 'request input loop' so it unloads the form properly). My question: Does VB provide some command that will end all running Subs (such as this one waiting for input), when the form is closing (and the User's input is no longer relevant to this instance)? Or, how can I cleanly escape that loop when the user doesn't actually provide any more input than to click the form X Close command?
Any suggestions or advice is greatly appreciated!
-
I won't go into asking why you are using a loop to wait upon user input as there many events that will capture user input but I will say that you should use the forms query unload event to set a form level variable to T/F your choice that you can test for inside of your loops and if the boolean variable = T/F then exit for/do/loop.
Good Luck
-
Thanks, VB, that worked. Long story on the loop. I hate the loop, but it seems to be the only way for me to accomplish what I'm trying to do. Maybe I will post for alternatives if I can get my thoughts together long enough to clearly explain what I'm trying to accomplish. That's another day.
I actually spent the whole day working on this form unloading issue and think I have a much better grasp now of the whole process (and where that 'Close' button fits in). It's working well now.
I do still have one question you might be able to help with. Whether using my command button to leave the form, or the Close button, the Terminate event is not firing. Might you have a guess as to why that might be? And is it inappropriate to put my 'Set form=nothing' statement in the Unload event instead?
Thanks for help.
Last edited by Shannon; 08-29-2009 at 01:48 AM.
-
Okay, when the user clicks on your button...
Code:
Private Sub CommandUnload_Click()
MyLoopFlag = True
Unload Me
End Sub
The unload statement is the only thing you need to have the form unload correctly. When that line of code is reached the following events happen...
Query Unload
Unload
Terminate
Query Unload is where you test to see how your program is ending and in some cases you can stop your form from unloading. (You can't stop it when OS tells program to close and query unload does not catch being ended by task manager.)
Unload is where you clean up any visual objects you created at runtime and most people also use it to clean up other objects like ADO connections and the like.
Terminate is the last chance to clean up non visual elements (ADO for example).
Now, if the above form was call with code like this...
Code:
Dim F As Form
Set F = New Form1
F.Show vbModal, Me
Then you would want to include this code after the F.Show
Hope I explained that well enough...
Good Luck
-
So when I just load a form normally, from another form ... when I'm done with it and use the unload statement, I don't need the 'Set Form2=nothing' line. It's not necessary. Is that correct?
-
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
Replies: 0
Last Post: 02-23-2006, 07:08 PM
-
Replies: 3
Last Post: 02-02-2006, 04:42 AM
-
By maheeru in forum VB Classic
Replies: 3
Last Post: 08-09-2005, 12:59 PM
-
By skyxmen in forum VB Classic
Replies: 2
Last Post: 09-04-2001, 02:51 PM
-
By Setya in forum VB Classic
Replies: 4
Last Post: 01-09-2001, 03:57 AM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks