Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 7, 1997

Close All Forms Before the End of a Program

It is well known that VB3 is not always as conscientious as it should be about unloading all the forms in an application whenthe application terminates. Because unloading all the forms for an application manually can be tricky, I have developed a small routine that can be called as a prelude to the End statement:

 
Sub Main ()
'
' Blah, blah, blah...our code here....
'
CloseForms
End

End Sub

Sub CloseForms()
        Dim iFormCount As Integer
        Dim i As Integer
        'Nothing's gonna stop us now....
        On Error Resume Next

        'Store the number of forms NOW 
        'because the count will change as 
        'we close them
        iFormCount = Forms.Count - 1

        'Step downward through the Forms 
        'Collection to ensure we get 
        'ALL of them...
        For i = iFormCount To 0 Step -1
                Unload Forms(i)
                Set Forms(i) = Nothing 
        Next
End Sub




The key here is to get the count of the number of open forms and then loop from that number down to make absolutely sure that all forms in the application are unloaded.

Joe Ackerman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date