For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > March 2004 > unwanted load event when checking is form visible









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author unwanted load event when checking is form visible
Mike

2004-03-28, 9:57 pm

Hi

VB6

Before I load form frmX I am trying to use

If frmY.Visible = True Then
Unload frmY
End If

in frmMain

But this is firing frmY's load event. How can I check that frmY is not
loaded without firing its load event prior to loading frmX (these are
modless forms, but I need to ensure that only one of them can be visible at
once [without making them modal])

thanks

Mike


Mike

2004-03-28, 9:57 pm

great ! Many thanks

Mike

"Bob Butler" <tiredofit@nospam.com> wrote in message
news:OzClXb0EEHA.2460@TK2MSFTNGP10.phx.gbl...
> "Mike" <mike@n-o--s-p-a-m.luusac.co.uk> wrote in message
> news:QSX8c.30$am.18@newsfe1-gui.server.ntli.net
>
> Just unload it; it does not hurt to unload a form that is not loaded

(except
> that the Initialize event will fire)
>
> your other option is to loop through the forms collection
> dim f as form
> for each f in forms
> if f is formY then unload f
> next
>
> --
> Reply to the group so all can participate
> VB.Net... just say "No"
>



Jeff Johnson [MVP: VB]

2004-03-28, 9:57 pm


"Mike" <mike@n-o--s-p-a-m.luusac.co.uk> wrote in message
news:QSX8c.30$am.18@newsfe1-gui.server.ntli.net...

> Before I load form frmX I am trying to use
>
> If frmY.Visible = True Then
> Unload frmY
> End If


For reference, touching any "built-in" property of a form will cause that
form to load. Touching user-defined properties will not cause the form to
load.

(If I've got that backwards--and I always seem to--correct me, someone....)


Bob Butler

2004-03-28, 9:57 pm

"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:O%23kYNm0EEHA.2640@TK2MSFTNGP09.phx.gbl
> "Mike" <mike@n-o--s-p-a-m.luusac.co.uk> wrote in message
> news:QSX8c.30$am.18@newsfe1-gui.server.ntli.net...
>
>
> For reference, touching any "built-in" property of a form will cause
> that form to load. Touching user-defined properties will not cause
> the form to load.
>
> (If I've got that backwards--and I always seem to--correct me,
> someone....)


you are right; touching any property related to the GUI (top, left, visible,
windowstate, hwnd, etc) causes VB to load the form because it needs it in
memory in order to get the property information. touching any property of
any control on the form does the same thing because to get to the control
the form has to exist.

you can call user-defined public properties & procedures without loading the
form as long as the code inside those procedures doesn't attempt to touch
any GUI-related property.

--
Reply to the group so all can participate
VB.Net... just say "No"

Mike

2004-03-28, 9:57 pm

Thanks to you both for this - useful for the beginner to know !
Mike
[color=darkred]
> you are right; touching any property related to the GUI (top, left,

visible,
> windowstate, hwnd, etc) causes VB to load the form because it needs it in
> memory in order to get the property information. touching any property of
> any control on the form does the same thing because to get to the control
> the form has to exist.


> you can call user-defined public properties & procedures without loading

the
> form as long as the code inside those procedures doesn't attempt to touch
> any GUI-related property.



MikeD

2004-03-28, 9:58 pm


"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:O%23kYNm0EEHA.2640@TK2MSFTNGP09.phx.gbl...
>
> "Mike" <mike@n-o--s-p-a-m.luusac.co.uk> wrote in message
> news:QSX8c.30$am.18@newsfe1-gui.server.ntli.net...
>
>
> For reference, touching any "built-in" property of a form will cause that
> form to load. Touching user-defined properties will not cause the form to
> load.
>
> (If I've got that backwards--and I always seem to--correct me,

someone....)

You've got it right. Just to ammend a little bit...

Not only properties but also intrinsic methods, and referencing controls
will automatically cause the form to load as well. Even within your own
user-defined properties and methods, if you use any of a form's intrinsic
properties or methods, or reference a control, the form will automatically
load. I don't know how many times I've seen programmers write a property
procedure like this:

Public Property Let SetText(MyText As String)

Text1.Text = MyText

End Property

as a work-around to the "auto form load" and then still can't understand why
it doesn't "work".

Mike


Bob Butler

2004-03-31, 4:30 pm

"Mike" <mike@n-o--s-p-a-m.luusac.co.uk> wrote in message
news:QSX8c.30$am.18@newsfe1-gui.server.ntli.net
> Hi
>
> VB6
>
> Before I load form frmX I am trying to use
>
> If frmY.Visible = True Then
> Unload frmY
> End If
>
> in frmMain
>
> But this is firing frmY's load event. How can I check that frmY is
> not loaded without firing its load event prior to loading frmX (these
> are modless forms, but I need to ensure that only one of them can be
> visible at once [without making them modal])


Just unload it; it does not hurt to unload a form that is not loaded (except
that the Initialize event will fire)

your other option is to loop through the forms collection
dim f as form
for each f in forms
if f is formY then unload f
next

--
Reply to the group so all can participate
VB.Net... just say "No"

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com