Results 1 to 9 of 9

Thread: load/unload and visibility of forms

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Resolved load/unload and visibility of forms

    in a form
    is load/unload the same as visibility =true /visibility=false
    Last edited by vb_student; Jan 15th, 2005 at 08:30 PM.

  2. #2
    Addicted Member
    Join Date
    Nov 2004
    Posts
    171

    Re: load/unload and visibility of forms

    That would be no. Load brings it into memory, Visible shows it to the user. As well as Show.
    Sherminator ~ I'll be back.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: load/unload and visibility of forms

    just discovered that the unload method actually unloads the form from the memory while the hide just hides the form.

    what i dont understand is that if you have a project with multiple forms,

    the project properties determines the startup object, however since all the other forms have their visibility set to true, then should not all the other forms be displayed behind the startup form?

    or do i have to explicitly tell the forms to show themselves by doing a
    fooformfoo.show()

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: load/unload and visibility of forms

    The other forms are not loaded and therefor not shown. And yes you can load and show a form by calling the Show method. You can also load a form using the Load statement:
    VB Code:
    1. Load Form2
    However that will only load the form not show it regardless if the Visible property is set or not. You still need to call Form2.Show after that.

    So what's the difference? Well sometimes you might want to load a form and keep it in memory but not showing it before a special event is raised. This might be because you have a lot of controls on the form and it takes a long time to load.

  5. #5
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: load/unload and visibility of forms

    Quote Originally Posted by vb_student
    do i have to explicitly tell the forms to show themselves by doing a
    fooformfoo.show()
    You are going the right way.

  6. #6
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: load/unload and visibility of forms

    You have done quite a lot of multiple posts on this topic.

    I answered one in another thread, but will do it again.

    A FORM gets loaded when you reference it. That means SHOW or LOAD - or even simply referencing a property or method of that form. So setting a form that is not loaded yet to visible will implicitly load that form.

    This can be a good and bad thing.

    When a FORM is loaded is the first time the form objects and code are loaded from the .EXE into memory.

    This was required in the days of "small memory" processors - when loading and unloading forms was required by the programmer to manage the application use of memory.

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: load/unload and visibility of forms

    thanks for all the replies, it has cleared my confusions. i will avoid posting similar questions in different posts.

    my last questions on this topic

    if you have unloaded a form, and you reference a public variable or function of that unloaded form then does that load that cause the form to be loaded into memory implicitly, since the variable/function can not be accessed unless it resides in the memory?

    obviously i understand that a form can not be destroyed,so my question to how to destroy a form is meaningless, correct?


    also at the begining is only one form loaded (the one pointed to by the project settings) into memory and the rest as the yare called?

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: load/unload and visibility of forms

    If you UNLOAD the form and then again reference a form variable or property, that form does get loaded.

    But the value will be re-initialized - don't think that the value that the form variable had initially will still be there - the UNLOAD cleared all that from memory.

    Destroy? UNLOAD pretty much destroys the form in memory. What level of "destroy" are you wondering about?

    We typically do not have a FORM loaded at startup, but instead a MAIN SUB in a MODULE. This SUB can determine certain things before any forms are loaded.

    For example, we want to detect if the APP is already running - so it doesn't run again. That's done in non-form logic.

    Also, there could be times you want an app to optionally run unattended - scheduled in the back ground. In that case, you want no screen interaction at all.

  9. #9
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    Re: load/unload and visibility of forms

    Quote Originally Posted by vb_student
    if you have unloaded a form, and you reference a public variable or function of that unloaded form then does that load that cause the form to be loaded into memory implicitly, since the variable/function can not be accessed unless it resides in the memory?
    No exactly. Reference to a form's public variables or methods will not implicitly Load the form unless one of the form's controls or built-in properties (e.g., Caption) are referenced. What it will do is implicitly instantiate the form object. That is, the Initialize event will fire, but the Load event will not.


    Quote Originally Posted by vb_student
    obviously i understand that a form can not be destroyed,so my question to how to destroy a form is meaningless, correct?
    I disagree. The form can be destroyed - as signified by the firing of the Terminate event. This occurs when the form is no longer visible and all references to it are set to Nothing.


    Quote Originally Posted by vb_student
    also at the begining is only one form loaded (the one pointed to by the project settings) into memory and the rest as the yare called?
    If the project's startup object is a form (it doesn't have to be), then only that form will be instantiated (brought into memory), loaded and shown - all others remain out of memory.


    I've noticed that some people seem to be confused by the term "loaded". There are two conotations to this word.

    1) Loaded into memory - instantiated (which makes available the form's public variables and methods);
    2) and Loaded as in the command "Load Form1" (which makes available the form's visual components - e.g., controls and form properties).

    #1 fires the Initialize event (the opposite of which is Terminate), #2 fires the Load event (the opposite of which is Unload).


    As usual, the MSDN provides an excellent resource in this article: Life Cycle of Visual Basic Forms

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width