terminating a program completely

how do u effectively terminate a vb program?
i created a program and it exits fine (i placed a button "exit").

the code is something like this :

sub cmd_ExitClick()
   end
end sub

of course it always exit whenever i press the exit button. but it leaves a zombie process (in unix term) in the task manager window. even its already closed. how do i effectively close/terminate it w/o leaving a track in the task man?. i stiil have to ctrl-alt-end-task the sucker.
LVL 3
iboAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mcriderConnect With a Mentor Commented:
unload all of the forms that have been loaded before you terminate...  When you do that, your VB program should end without the END statement.

Cheers!
0
 
JuiletteCommented:
Mcrider is correct...you shouldn't use End.
If you need the code to supplement his answer, here it is.

'create a bas module
'
Public Sub UnloadAllForms()
      Dim Form As Form
               For Each Form In Forms
                        Unload Form
                  Set Form = Nothing
         Next Form
End Sub

'
'==================================================
'place this in your exit event
'
      Call UnloadAllForms
0
 
mark2150Commented:
You also want to shut down any timers, close all files and databases as well.

M
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
iboAuthor Commented:
i only have one form.. the main form.
i didnt use gdi.

so..
its must be

sub my_exit
  unload Main_form
end sub

?
0
 
mcriderCommented:
Yes ibo, you got it!
0
 
JuiletteCommented:
Unload Me
'saves typing form name
'Me refers to active form and since you
'ony have one...you got it.
0
 
mark2150Commented:
Actually the form shown in juliette's first example is preferred. You can use it as a common routine and it will work with any number of forms, including just one. Since it automatically adapts as forms are added you never have to fiddle with it in later versions of your program where you might actually add a new form. The execution difference doesn't matter since this is a one-time use routine at shutdown.

The only modification I would make to Juliette's code is that using a keyword as a variable name is considered a no-no. Instead of;

DIM FORM AS FORM

I'd code:

DIM FRM AS FORM

This will help the compiler keep things straight and you loop becomes:

FOR EACH FRM IN FORMS
  UNLOAD FRM
  SET FRM = NOTHING
NEXT FRM

M
0
 
mcriderCommented:
It doesn't matter whether you use Unload Me, Unload Main_form, or a for each unload...

As long as you unload all of forms that you have loaded.

Cheers!
0
All Courses

From novice to tech pro — start learning today.