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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to unload a form (not just hiding) 2

Status
Not open for further replies.

xinyin

Programmer
Jan 16, 2003
81
HK
Hello,
I have 2 forms, say formX and formY. When formX is loaded, it calls formY to open, and later it closes formY. The code is something like this:
formX_Load()
formY.show
(code...)
formY.hide
end sub
I know that formY is still there (in the memory) after the .hide, the proof is during the test run when I shut down formX VB6 is still in the "play" mode, implies that there is something still hanging there. I don't find a way to shut it totally. I tried .close and .unload and doesn't work (unload is an event for formY, but I can't use it as a method) and can't find anything else useful in the object browser. I hope if someone can tell me a way to unload this formY.
 
Instead of formY.Hide, use Unload(formY)

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Use: [tt]Unload formY[/tt]

Unless it's a function and you want it to return a value, don't use parens.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
It works! Thanks!
I find out that the "()" is not required. Just make the syntax "Unload formY" will be ok.
 
True,

It will work w/ parens if there is only one param... but it's a bad habit...

It will actually be read:
Unload (FormY)

*Note the space, which treats (FormY) as an evaluation, similar to (1 + 1) * 2, where (1 + 1) is evaluated before multiplying by 2...

But if there are 2 or more params, it will cause an error:
Unload(FormY, X)

The exception would be to use Call, which treats a sub as a function:
Call Unload(FormY, X)

To confuse things more... ;-)
In .NET you do use ()'s for everything... which actually eliminates this confusion, (unless you are like the rest of us who are used to the current rules)

*Note, there is no Param Y in unload...
Do as Tracy suggested and use:
Unload formY

Hope this didn't cause too much confusion ;-)

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
(unless you are like the rest of us who are used to the current rules)

I code back and forth in VB, VBScript and Javascript. I'm constantly getting errors in VB and VBS for using parens where I shouldn't (among other things). I've never understood why MS couldn't make the use of parens consistent with 90% of the programming languages out there.

[tt] [green]'is this a comment or a literal?'[/green][/tt]

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

tsdragon


if Microsoft acceeded to your request they would have to fire Most of their Handicappers !!!!!!



plwallace
 
Mastery of the vagaries of VB syntax enables one to charge more money for one's time.
 
add this

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'release variables/objects
'most especially connections and recordsets and the like
'set variable = NOTHING
End Sub

this may seem an added burden but i tell this would be very beneficial especially when u too many forms to manage and your codes have grown huge...

 
You can also use the Unload event for this. QueryUnload is generally used when evaluating the UnloadMode parameter, e. g.:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode <> vbFormCode Then
   Cancel = True
End If
End Sub
This will prevent a form from unloading unless it encounters an "Unload Me" or similar statement. In other words, it will disable the Close button, the Alt-F4, and so on.

Bob
 
Thanks Bob! That's something I didn't know! [star]

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top