Close All Forms Before the End of a Program

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.

See also  10 Best Apps to Help You Read More Books in Less Time

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist