Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A Clean Exit from a VB 6.0 App

Status
Not open for further replies.

jake007

Programmer
Jun 19, 2003
166
US
Occasionally, when I exit my application with the "Close" X in the upper right of my program window, the application does not completely shut down. the only way to close it is Ctr-Alt-Del, end program. I also have a Menu Selection which exits the program but I need to put the end function in twice to ensure that the program closes properly. How do I make sure that the entire application shuts down with either the "X" close or my menu command.

I beleive it has something to do with not properly unloading forms, but not sure.

Thanks, Jake
 
In your menu just place code to unload the form,

Unload Form1

This will call the queryunload event, which is also called when you click the 'x'. Now you canplace code in one spot to end the program.

I usually have a 'shutdown' sub that makes sure all forms have been unloaded and any other cleanup is done (close all database connections, etc.) then I hjave 'End' as the last line in the 'shutdown' sub.

Here is an example.

Code:
Public Sub ShutDown(pTarget As Form)
'// Unloads all forms and closes the connection.
   Dim i As Integer
   
   DoEvents
   g_bolShutDown = True
   pTarget.MousePointer = vbHourglass
   Close_Connection
   '// Unload all loaded forms.
   For i = Forms.Count - 1 To 0 Step -1
      Unload Forms(i)
   Next i
   pTarget.MousePointer = vbNormal
   '// Ends the program.
   End
End Sub


Thanks and Good Luck!

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top