Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VB6 Form unload/ load using Command Buttons

505 views
Skip to first unread message

Cliff Bailey

unread,
Jan 29, 1999, 3:00:00 AM1/29/99
to
Am I missing something here? I'm using command buttons to load a form
(form2 in this example) and another command button to unload form2. This
will work a few time but then bombs with a a run-time error 364 'Object was
unloaded'.

Here is the example code:

Private Sub Command1_Click()
Load Form2
End Sub

Private Sub Command2_Click()
Unload Form2
End Sub

I performed the test above because I have a main menu form that loads a
form via a command_click (the form remains hidden) and the form is unloaded
using an unload statement. I've tried the unload statement within the
hidden form and the main menu that called it, but the results are the same.

Any ideas are much welcomed!

Thxs in advance!

Douglas Marquardt

unread,
Jan 29, 1999, 3:00:00 AM1/29/99
to
Hi Cliff:

What you describe should work no problem, I suspect that somewhere else in
your code (perhaps in Form2 itself) is where the error is occuring.

To test this, start a new project and add another form so you have Form1 and
Form2.
Then add two command buttons and cut and paste your code below into form1.
Run the project - it should work just fine.

Doug.


Cliff Bailey wrote in message
<#5t3Tw8S#GA....@uppssnewspub04.moswest.msn.net>...

Rob R. Ainscough

unread,
Jan 31, 1999, 3:00:00 AM1/31/99
to
I have similar problems with Forms. VB documentation is very poor regarding
when/if a form truely gets unloaded and exactly when this happens
(especially confusing with modeless forms). Also, doing an Unload Me will
remove the form from the standard Forms collection (check the built in
Forms.Count property), HOWEVER, the Unloaded forms Terminate event is NOT
triggered until ALL forms are unloaded and the application Ends. This is
very odd behavior and not expected in my humble opinion. So the forms never
really exist in the built in Forms collection, but do exist in my Forms
collection. This is a big issue because I have yet to figure out a way to
truely remove the form from my app's forms Collection that I manange. Which
means my forms collection just keeps growing and growing (aka memory hog).
With modal forms this is not a problem because I can remove the form from my
collection after I load/show it. But with modeless forms there is NO good
point to really accomplish this. At least I haven't found one.

Barry Evans

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
I find myself re-reading "Life Cycle of Visual Basic Forms" in the VB
Programmers's Guide whenever threads like this shatter my confidence that I
do actually understand this issue.

It is at Page 371 of my Vb5 VB Programmers's Guide.

For Vb6 it is buried away at:

MSDN Library Visual Studio 6.0
Visual Basic Documentation
Using Visual basic
Programmer's Guide (All Editions)
Part 2: What Can You Do With Visual Basic?
Programming with Objects
Creating Your Own Classes
Life Cycle of Visual Basic Forms

It's a good read!

Barry Evans
Canberra, Australia
----------------------------

Rob R. Ainscough wrote in message ...

CB

unread,
Feb 1, 1999, 3:00:00 AM2/1/99
to
Hi Doug:

You're right, this should work just fine! I did exactly your suggestion
before I posted this problem that I was experiencing. I would get the
run-time error in Form1 (Command_Click for the 'load Form2).

The bizarre thing is, I'm not receiving the error now with the same exact
code (I feel like I'm loosing my mind). I would have never posted this if
I wasn't totally suprized. I will have to continue testing this throughout
the day. The only difference between now and then is a system re-boot.

Thanks again,

Cliff


Douglas Marquardt wrote in message
<#ZYL8P9S#GA....@uppssnewspub05.moswest.msn.net>...


>Hi Cliff:
>
>What you describe should work no problem, I suspect that somewhere else in
>your code (perhaps in Form2 itself) is where the error is occuring.
>
>To test this, start a new project and add another form so you have Form1
and
>Form2.
>Then add two command buttons and cut and paste your code below into form1.
>Run the project - it should work just fine.
>
>Doug.
>
>

0 new messages