i created an exe with multiple forms but when you close it down it still stays running in the task manager. any idea whats causing this?
Printable View
i created an exe with multiple forms but when you close it down it still stays running in the task manager. any idea whats causing this?
your not unlaoding your forms, and objects :)
tell us what your app is, whats controls it contains etc
Pino
This is what it's called "Memory leak". There are objects or even entire form(s) which were not unloaded from memory. You should never use the END instruction to finish your application. Be sure you unload all the forms, and destroy each object you've loaded into memory. Once you've done this... your program will just end pacefully.
erm its a login/register form
theres 4 forms, main menu, login form, register form. and a terms and conditions form.
starts on main menu, theres 2 radio buttons and a command buttong. dpending on what radio button is choosen the login or register form will open. and the terms and conditions form loads by clicking on a label on the register form...sorry im rubbish at explaining...
Put this in your Unload event:
Code:Dim Form As Form
For Each Form In Forms
Unload Form
Next
your not rubbish, if its simple could you post me yor app? as has been stated you may be using END which is bad practice.Quote:
Originally Posted by ultimate165
Pino
do i put that exact code?...
Here you have a thread to shed some light on you. You might learn some interesting things out of this thread.
http://www.vbforums.com/showthread.p...hlight=in+case
could you zip up all of your project files, and uplaod it.
Pino
i didnt have any end i just closed the app using the X lolQuote:
Originally Posted by Pino
edit: where do i upload to? its only 5kbs
nope still cant get it done.
it works for the main form but i cant get the others unloaded
if anyone has msn contact me on [email protected] and ill send you over the files so you can show me what to do :) thanks
still cant fix it :(
You really shouldn't post your email address since spammers can pick it up.
It's been suggested that you create a zip file and upload it here so we can take a look at it. If you can create a zip (or rar) file then just click the Manage Attachments button and it will help you complete the upload.
When you are composing your reply you'll see a Manage Attachment below where you are typing...Quote:
Originally Posted by ultimate165
thanks for that. well theres the files. has all the forms and everything so if someone could correct my mistakes and tell me what im doing wrong so i can understand it, it will save me goin wrong in the future. thanks :)
Instead of Unload Form use Unload Me instead...
ok thanks. do i just put Unload Me in the same place i had all the unload form stuff?
damn this is frustrating. can anyone at all point me in the right direction and explain what i need to do and explain how it works?
ok, what is happening is when you close your app your app isnt unloading all of its 'bits' this is why it is still appearing in your task menu.
The simple way to solve this is to unlaod all the forms manually. using a very simple loop here.
VB Code:
Dim Form As Form For Each Form In Forms Unload Form Next
'Taken from above post
or you can simply put the following statement in all of your forms unlaod events
VB Code:
Unload Me
now all you need to do is add that to each of your form_unload events, and its should be ok.
I'd fix it but i havent insatlled Vb6 on this machine since i re-formated .Net is taking over :p
Hope that helps
thanks ill give it a go now... ive been putting the code into the exitprogram part :blush:
[QUOTE=Pino]
VB Code:
Dim Form As Form For Each Form In Forms Unload Form Next
ok where do i put this code? ive put it at the top of the code in declarations and nothing, ive also tried putting it in the form_unload() part but i get compile errors :(
and ive tried
Private Sub Form_UnLoad()
Unload Me
End Sub
but i get an error saying "procedual declaration does not match description of event or procedure having the same name" which is problyc cause i dont have a button that unloads the form. i just want to end the program by closing it using the X at the top of the window
I have a command button that gets clicked to end the app. Here is the code for the module
VB Code:
Option Explicit Private Sub cmdExit_Click() Dim frm As Form For Each frm In Forms If frm.Name <> Me.Name Then ' Unload this form LAST Unload frm Set frm = Nothing End If Next Unload Me End Sub
Sorry Pino but putting Unload Me in the form's Unload event isn't going to do anything since at that point the form is already unloading. Here is what you want to do. Put the following code in each forms QueryUnload event
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
VB Code:
Dim frm As Form For Each frm In Forms If frm.Name <> Me.Name Then Unload frm Set frm = Nothing End If Next Unload Me Set Form2 = Nothing ' Form2 should be changed to the name of the form where the code is
Or better yet add the following sub to a code module.
and call it from each form's QueryUnload event like thisVB Code:
Public Sub UnloadAllForms(AForm As Form) Dim frm As Form For Each frm In Forms If frm.Name <> AForm.Name Then Unload frm Set frm = Nothing End If Next Unload AForm Set AForm = Nothing End Sub
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) UnloadAllForms Me End Sub
Actually, This is redundant since the form is already being unloaded in the unload event
VB Code:
Unload AForm Set AForm = Nothing
im getting so confused :(
heres the forms i have and everything can someone look thru them and just tell me what i should take out and what i should put in? thanks
I'm not surprised. Every time someone asks about closing forms (which is actually a very simple process) several people always chime in and often split hairs about what is right and what isn't which can be very confusing. So don't feel bad, it's not you, it's us.Quote:
Originally Posted by ultimate165
I can't open rar files but if you can create a zip file I could help more.
ok heres a zip...
Try this
You should start the code in Sub Main() in a module. Change the startup form to sub Main in project properties.
Then, in Sub Main, you would allow the user to log in. If he passes the login, you would load the next form. If he fails the login, then you don't do anything, and nothing is shown. Then, you only have to worry about the main form unloading.
Here is what I do. I give them 4 chances to get it right:
VB Code:
Sub Main() LoginSucceeded = False Do Until LoginSucceeded = True Or lcnt = 4 frmLogin.Show vbModal Loop If LoginSucceeded = True Then frmMain.Show End If End Sub
Also, the screens didn't look right at 1024x768 resolution.
wow thanks. it seems to work now :eek: the only thing is i dont understand what i was doing wrong?
also the reason the interface may of looked funny was because i was using a custom font... how to i make it so other people get the custom font downloaded to thier font folder when they open up the program?
or better still be able to view the font without them downloading it
Basically there was something that was still in memory and wasn't unloaded. Lets take the smallest possible example:
- you have two forms, Form1 and Form2
- Form2 is opened from Form1
- Form2 has a button with code Me.Hide
- clicking this button will hide Form2, but not unload it
- you close Form1
- program stays open, because Form2 is still in memory although you can't see it
And the end result is that the program doesn't close. This is the case every time a program doesn't end properly: something is still in memory.
Another common mistake:
VB Code:
Private Sub cmdClose_Click() Unload Me SaveFile Text1.Text End Sub
The problem here is that the form is unloaded once, but when you call Text1, the form is reloaded into the memory. And so the program doesn't end.
To properly unload all forms and allow your program to terminate follow these simply rules (and code)
in a Module place this code
VB Code:
Public Sub UnloadAll(Optional activefrm As Form) Dim frm As Form Dim ctl As Control On Error Resume Next For Each frm In Forms ' Don't unload active form or we will reload it when we return to it ' Allow active form to unload itself If frm.Name <> activefrm.Name Then ' This is extra protection and may not be needed For Each ctl In frm.Controls Set ctl = Nothing Next Unload frm Set frm = Nothing End If Next End Sub ' In your main form include this call in your Unload event (Not the Query_Unload Event) UnloadAll Me ' If you start your program from Sub Main just use this code at the end of your mainline code UnloadAll
And thats it!!! Your program will unload all forms and allow your program to terminate.
You have to include and install custom fonts if you use them in your app. I think Inno does it for you, but I'm not sure.
but how do i get them to install on someone elses computer when they open up the application? dont understand any of this stuff lolQuote:
Originally Posted by dglienna
This is why he suggested to make a setup program (InnoSetup creates installation programs).
Though admittedly he forgot to mention the word "setup" :)
ultimate165,
You actually have to do some of the reasearch, believe it or not...
Read the help section of Inno Setup on Font Installation.
hehe ok. ill go and get inno "setup" now :D
I left off the word Setup because there is Inno Setup and Inno Script, which writes the code for Inno Setup.