Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stupid form unloading question 3

Status
Not open for further replies.

OrthoDocSoft

Programmer
May 7, 2004
291
US
Folks,

Some of the forms in my program "load" and "activate" and then I am done with them, and want them "gone."

Since strongm has embarrassed me away from using "end" (rightfully, lol), I'm trying to do things more correctly.

So when I'm done with a form, I use:

Code:
Unload frmMyForm
set frmMyForm = nothing

and for awhile, I was placing this as the last lines of the Form_Load procedure, but felt weird about it, because how can you ask a form to become "nothing" before you have finished "loading" it. See?

Should I put this code in Form_Activate, which is, I think, the last thing to happen before the form appears?

Thanks,

Ortho

[lookaround] "you cain't fix 'stupid'...
 
OK, just realized that putting unload/set to nothing in Form_Activate won't work, because you can never really see the form, which I sometimes need to do. Maybe I just need to think about this some.

[lookaround] "you cain't fix 'stupid'...
 
No, that code belongs under the button that closes the form or in the unload or terminate event(Terminate event would be only Set Me = Nothing).



Good Luck

 
I'm not understanding this.

For me the whole purpose of a form is that it provides a visual interface and, by shutting it down before it is displayed, you are clearly not using that basic functionality.

Presumably the only thing that it is doing is running the Form_Initialize, Form_Load and Form_Activate code and then shutting down.

Would you not get the same result running that code from a module that doesn't have the overhead of a form Load/Unload and has no requirement to handle getting rid of the form upon completion?
 
Golem,

That is a good point, and the conclusion to which I am rapidly advancing.

Ortho

[lookaround] "you cain't fix 'stupid'...
 
You know, how I got in this mess is that I always start a project with a form, and I always start putting my "basic start-up" stuff in the form_load procedure.

How and where do you all start your programs?

Ortho

[lookaround] "you cain't fix 'stupid'...
 
Depends what you need to do in your 'basic start-up'.

I generally use Sub Main() but I've not had to write a VB6 app from scratch in what seems like ages...

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
OrthoDocSoft said:
How and where do you all start your programs?

Almost always with a Sub Main in a module. My Sub Main procedures do all sorts of things like establish paths to databases, configure the environment, perform integrity checks, etc., before any thought of talking to the user (i.e. displaying a form) is even contemplated.
 
Golem, I do that too, but usually in a form_load procedure, and I'm seeing that this is bad. It is true, isn't it that a form has to be the start-up object and that a module cannot be?

[lookaround] "you cain't fix 'stupid'...
 
No, if you use Sub Main() in a module you can set that a the startup object.

Hope this helps

Andy
---------------------------------
[green]' Signature removed for testing purposes.[/green]

 
Hey VB5,

you know, you say you put

set me = nothing

in your form_terminate events, but if you are IN form_terminate, isn't it a given that the form is getting set to nothing? So isn't this code a bit redundant?

Just trying to sort this all out before I die.

Ortho

[lookaround] "you cain't fix 'stupid'...
 
No. It is not true.

Under the General Tab of your project's properties (click on Project and select Properties) you can select the startup object ... either Sub Main or a form.

Sub Main must of course exist in a module for you to select it.
 
Harley,

That's great! I'll get right too that.

Ortho

[lookaround] "you cain't fix 'stupid'...
 
Well I just finished moving the general code to a module, specifically, sub Main. This FEELS so much better and makes more sense.

You have no idea the contortions I was making around loading, unloading, hiding forms for nothing, so I feel as though I've had a nice hot bath, and am now clean and beaming.

Was that TMI?

Thanks to all

Ortho

[lookaround] "you cain't fix 'stupid'...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top