General discussion

Locked

Program won't exit when closed

By dartfrogs404 ·
I created a program in Visual Basic using Visual Studio, with multiple forms. The first form calls the individual other forms by "formx.show". When finished with the forms, I use "formx.hide". This way the variables used in each form are available to each others.

The code to exit consists of:

Public Sub UnloadAllForms()
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
End Sub

then to call an exit is use:
Call UnloadAllForms
End


However, when I create an exe from this program, whenever I load and unload a form inside the program, exit only makes the program disappear. I must exit the program using the Task Manager.

How do I get it to exit by itself?

This conversation is currently closed to new comments.

7 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Program won't exit when closed

by zeshanzia In reply to Program won't exit when c ...

The form from which you are calling others is your parent form. You must Exit or terminate the application with this main form.

Use 'End' keyword in your Main Parent Form and provide some mechanism like button for that purpose

Collapse -

Program won't exit when closed

by dartfrogs404 In reply to Program won't exit when c ...

That code is already placed in the parent form. Thanks anyways.

Collapse -

Program won't exit when closed

by tclere In reply to Program won't exit when c ...

Observation: You should not use the object name "Form" since it is a reserved keyword. Instead, try something like:

Dim myForm As Form
For Each myForm in Forms...

Collapse -

Program won't exit when closed

by dartfrogs404 In reply to Program won't exit when c ...

Same problem as before. Thanks for trying.

Collapse -

Program won't exit when closed

by MadestroITSolutions In reply to Program won't exit when c ...

I tested your code and It works fine (assuming these are standard forms, not MDI), which means the problem is not here. You must be doing something else in some other place that is causing the program to crash and stay as a process.
Do this:

- Recompile
- Check the rest of your code

if that doesnt work, then reinstall VB.

By the way, consider the tip on answer #2, dont use reserved keywords, and try changing your approach. Why not use an MDI form? MDI forms will close their child windows automatically. You can preserve the values entered in your forms in other ways, like the registry, or global variables in a module, or a database perhaps. It will make your life easier. BELIEVE ME, been there... lol, good luck!

Collapse -

Program won't exit when closed

by dartfrogs404 In reply to Program won't exit when c ...

This problem occurs on two seperate computers. I tried uninstalling and reinstalling Visual Studio, still no luck. I'm not farmilliar with MDI forms, although i will try that. Also, i'll preserve my data using global variables, because apparentlyhiding and showing forms isn't the best way to do it, that i didn't know. Thanks for your help.

Collapse -

Program won't exit when closed

by dartfrogs404 In reply to Program won't exit when c ...

This question was closed by the author

Back to Web Development Forum
7 total posts (Page 1 of 1)  

Related Discussions

Related Forums