Re: Unload vs End Statement
Hello,
The Unload statement frees up memory better than END.But to close databases you have to set the recordset property to "Nothing"
Bye
Re: Unload vs End Statement
I know that in order to close databases I must set the recordsets to nothing and I have already done it. But my question is that:
I want to terminate the program execution immediatelly when an error occurs. So, what is the best way to do so? Just to use End st
Re: Unload vs End Statement
Hi
Depending on the type's of components used in your project - the 'END' statement doesn't usually free up any memory ! It's a definite no-no as far as component based development goes and I haven't seen a single good argument in favour of using an 'END' statement anywhere in code.
Why not simply unload all your forms and explicitly release your objects when you're finished with them ? It certainly makes debugging a whole lot easier.
Chris Eastwood
CodeGuru - the website for developers
http://www.
Re: Unload vs End Statement
Dear Chris,
I did release my objects when I finished with them, but my question is what to do when an error occurs suddenly. I trap this error but what is the next step to do in order to close the program? To write all the fragment of code for closing all the databases AGAIN? Doesn't the END statement do it automatically?
Michael Vlastos
Company MODUS SA
Development Department
Athens, Greece
Tel: +3-01-9414900
Re: Unload vs End Statement
This is straight from the MSDN :
---
Note The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.
---
I wouldn't trust them saying that all objects are cleared down / memory is freed - I know for a fact that if you use any subclassing or third party controls/dlls that an end-statement is like jumping out of a moving car to finish your journey - it may be ok but the chances are somethings going to crash sooner than later.
The best way to quit your program would be to have a function that does all the relevant tidying up work - even if it's as simple as causing your main form to unload which then releases all your variables / api handles / whatever.
eg.
'
' In a code (BAS) module
'
Sub TidyUpAndQuit()
Dim frm as Form
for each frm in forms
unload frm
set frm = nothing
next
End Sub
Make sure that all your Form_Unload procedures are clearing down any relevant object handles (set xx=nothing) and you shouldn't go far wrong.
Chris Eastwood
CodeGuru - the website for developers
http://www.codeguru.com/vb