|
-
Jul 15th, 2009, 05:02 AM
#7
Junior Member
Re: Correct procedure for declaring variables
Then what I would want to do is before the "End Sub" I should have "x = Nothing" and "y = Nothing", and then when "End Sub" runs
Like si_the_geek said, native variables (i.e. integers, long, string, double, date etc.) does not need to be released/set to null, vb gracefully deal with them by itself, the only thing you need to warry about setting to null are variables you create as objects or were created with new or used set on it)
Code:
Private Sub foo()
Dim fso As New FileSystemObject
Dim x As Object
Dim i As Integer
<some code>
Set fso = Nothing
Set x = Nothing
End Sub
if your fun function funCrashAndUnload is releasing all forms including the form the function is declared in then you you do a simple check like to protect from error
Code:
If Not mAVariable IsNothing Then
mAVariable = "foo"
End If
I'm a bit confused still as to how subroutines can finish running after I've unloaded their parent form...
well i hope i am right and i manage to explain right : VB when you call the unload event, simply exceute all that is there mark the form to be relesed, then return to complete the rest of the code, once that function is finished the form reference to the form is cleared and destroyed.
(i am sure its not the best explanation but i hope it help you understand)
the only code that stop execution of code is "Exit Function"/"Exit Sub", "End" and err.Raise
Edit: Ops took too long to type untill I see all was clarified
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|