Close All Forms Before the End of a Program

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

 Sub Main ()'' Blah, blah, blah...our code here....'CloseFormsEndEnd SubSub 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         NextEnd Sub

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

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: