Helpful Information
 
 
Category: Visual Basic Programming
How to exit a program

I know it's kind of lame and such, but i still don't know, so i'm asking.
What's the function to call when i want to quit my program?
That is, which function should i connect to my "Quit" button in my program? :)
I tried exit() and quit() but none of em worked, please help, i can't seem to find any help on this online either. :confused:

unload the form, and then end

unload me
end

Be sure to unload all loaded forms before you call end.

VB doesn't have the best memory management and calling end doesn't always clean the memory properly if there are still loaded forms present.

Remember you need to put an End command in the Form_Unload event as well. This is key.

Hi All,

Hope someone can provide more info on closing VB apps.

I have an application with dozens of forms and child forms, and using over 20 OCXs...once compiled the exe is around 10 MBs..

under development environment i can "End" the application properly....but when compiled and execute it, when i end the application, all the forms are gone, but under the "Task Management" utility in win2000 (CTRL + ALT + DEL) i can still see my app is running.


in my MDI parent form_unlod, i use


for each obj in forms
Unload obj
next

end


but after some reading and etc... i used




Public Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Declare Function PostMessageByNum& Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As _
Long, ByVal wParam As Long, lParam As Long)

Const WM_CLOSE = &H10
Const TARGET_CLASS_NAME = "ThunderRT6Main"
Const TARGET_WINDOW_TEXT = "Project1"

....Form Unload event (MDI parent)....
for each obj in forms
Unload obj
next


hTarget = FindWindow(TARGET_CLASS_NAME , TARGET_WINDOW_TEXT)
' The following line will close the app.
' You could instead set up a subclasser here.

If hTarget Then Call PostMessageByNum(hTarget, WM_CLOSE, 0, 0)

end




with the above, i can end the VB App.

any comments?

Thanks and Best Regards










privacy (GDPR)