dcsimg
Results 1 to 5 of 5

Thread: Set Form = Nothing is realy necessary?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2018
    Posts
    17

    Set Form = Nothing is realy necessary?

    Hi, guys!

    Please see:

    Code:
    Dim F as Form
    Set F = New Form1
    F.Show, Me 'Non Modal
    Set = F Nothing 
    Is the last line realy necessary?
    Set = F Nothing

    Regards!
    Last edited by hennyere; Sep 11th, 2019 at 09:03 AM.

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,870

    Re: Set Form = Nothing is realy necessary?

    Without testing:
    Set = Form1
    ...and....
    Set = F Nothing

    definitely results in a compile-error.....
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2018
    Posts
    17

    Re: Set Form = Nothing is realy necessary?

    I am sorry:
    Set F = New Form1

  4. #4
    Hyperactive Member
    Join Date
    Feb 2017
    Posts
    409

    Re: Set Form = Nothing is realy necessary?


  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,277

    Re: Set Form = Nothing is realy necessary?

    Barring that example shown in the link in post #4, I think the simple answer is that it isn't a bad idea to explicitly set forms to nothing. In other cases, you may want to ensure that and here is an example.

    If you declare variables, objects, and other things in the form's declarations section, they are still 'alive' when a form unloads unless:
    1. You explicitly destroy/release them the before the form unloads
    2. Set the form to nothing, which should release objects
    3. The form is the last one in the project to unload/close

    The declarations section of a form remains 'alive' until the form is set to Nothing or project terminates. This is by design. A form does not need to be shown, only loaded, to access it and its data.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width