|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Shut Down Program with Multiple FormsHello. I have a program that uses nine forms. Is there a way to Unload all
of them with a single line of code? Or do I have to use the Unload statement nine times to be sure they are all unloaded? TIA. Jim. "Jim Richards" <JWRicha***@satx.rr.com> wrote in message You have to unload each but you can use the forms collectionnews:uMohe.64461$AE6.12530@tornado.texas.rr.com > Hello. I have a program that uses nine forms. Is there a way to > Unload all of them with a single line of code? Or do I have to use > the Unload statement nine times to be sure they are all unloaded? > TIA. Jim. dim f as form for each f in forms unload f next IMO it's sloppy coding, but it works -- Reply to the group so all can participate VB.Net: "Fool me once..."
Show quote
"Bob Butler" <tiredofit@nospam.com> wrote in message Why do you consider that sloppy?news:uQhjhvJWFHA.4056@TK2MSFTNGP15.phx.gbl... > "Jim Richards" <JWRicha***@satx.rr.com> wrote in message > news:uMohe.64461$AE6.12530@tornado.texas.rr.com >> Hello. I have a program that uses nine forms. Is there a way to >> Unload all of them with a single line of code? Or do I have to use >> the Unload statement nine times to be sure they are all unloaded? >> TIA. Jim. > > You have to unload each but you can use the forms collection > > dim f as form > for each f in forms > unload f > next > > IMO it's sloppy coding, but it works -- Mike Microsoft MVP Visual Basic
Show quote
"MikeD" <nob***@nowhere.edu> wrote in message Because it's a seldgehammer approach. It makes sense to me for MDI appsnews:eQdIAyNWFHA.3176@TK2MSFTNGP12.phx.gbl > "Bob Butler" <tiredofit@nospam.com> wrote in message > news:uQhjhvJWFHA.4056@TK2MSFTNGP15.phx.gbl... >> "Jim Richards" <JWRicha***@satx.rr.com> wrote in message >> news:uMohe.64461$AE6.12530@tornado.texas.rr.com >>> Hello. I have a program that uses nine forms. Is there a way to >>> Unload all of them with a single line of code? Or do I have to use >>> the Unload statement nine times to be sure they are all unloaded? >>> TIA. Jim. >> >> You have to unload each but you can use the forms collection >> >> dim f as form >> for each f in forms >> unload f >> next >> >> IMO it's sloppy coding, but it works > > Why do you consider that sloppy? where you may have some unknown number of copies of a form but for most apps I prefer code that explicitly releases any resources it allocates. Doing the mass unload may mask a bug that causes a form to not be unloaded when it should. If you aren't keeping track of what you are doing then IMO it's sloppy. -- Reply to the group so all can participate VB.Net: "Fool me once..."
Show quote
"Bob Butler" <tiredofit@nospam.com> wrote in message I can't agree 100% with you on that. Maybe about 90%.news:eUz2ADOWFHA.2128@TK2MSFTNGP14.phx.gbl... > "MikeD" <nob***@nowhere.edu> wrote in message > news:eQdIAyNWFHA.3176@TK2MSFTNGP12.phx.gbl >> "Bob Butler" <tiredofit@nospam.com> wrote in message >> news:uQhjhvJWFHA.4056@TK2MSFTNGP15.phx.gbl... >>> "Jim Richards" <JWRicha***@satx.rr.com> wrote in message >>> news:uMohe.64461$AE6.12530@tornado.texas.rr.com >>>> Hello. I have a program that uses nine forms. Is there a way to >>>> Unload all of them with a single line of code? Or do I have to use >>>> the Unload statement nine times to be sure they are all unloaded? >>>> TIA. Jim. >>> >>> You have to unload each but you can use the forms collection >>> >>> dim f as form >>> for each f in forms >>> unload f >>> next >>> >>> IMO it's sloppy coding, but it works >> >> Why do you consider that sloppy? > > Because it's a seldgehammer approach. It makes sense to me for MDI apps > where you may have some unknown number of copies of a form but for most > apps > I prefer code that explicitly releases any resources it allocates. Doing > the mass unload may mask a bug that causes a form to not be unloaded when > it > should. If you aren't keeping track of what you are doing then IMO it's > sloppy. > I do agree that forms should be unloaded when they are no longer needed. That's just proper memory and resource management. But I see nothing wrong with (nor consider it sloppy) having that code in the main form's Unload event. Even in a non-MDI app, there may be several forms loaded (perhaps shown, perhaps not) when the main form gets closed. Hence, the app should terminate. -- Mike Microsoft MVP Visual Basic "MikeD" <nob***@nowhere.edu> wrote in message <cut>news:Ol92FPOWFHA.3488@tk2msftngp13.phx.gbl > I can't agree 100% with you on that. Maybe about 90%. <g>> I do agree that forms should be unloaded when they are no longer Right, and the cleanup code should handle them individually, closing them in> needed. That's just proper memory and resource management. But I see > nothing wrong with (nor consider it sloppy) having that code in the > main form's Unload event. Even in a non-MDI app, there may be several > forms loaded (perhaps shown, perhaps not) when the main form gets > closed. any order necessary and calling any special code to handle form-related resources, etc. IMO that's an order of magnitude better than just blindly unloading all forms. It's not that I put a big emphasis on this - using the loop is certainly better than nothing and probably quite sufficient in just about every application. I just consider it a much less rigorous approach than doing specific cleanup operations. > Hence, the app should terminate. As all good apps should <g>-- Reply to the group so all can participate VB.Net: "Fool me once..." |
|||||||||||||||||||||||