Results 1 to 6 of 6

Thread: [RESOLVED] [VB6] - Reload a form

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Resolved [RESOLVED] [VB6] - Reload a form

    it's possivel reload the actual form?
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [VB6] - Reload a form

    It is possible to reload any form provided it is not already loaded.

    What does "the actual form" mean?

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - Reload a form

    Quote Originally Posted by Hack View Post
    It is possible to reload any form provided it is not already loaded.

    What does "the actual form" mean?
    i have 1 game. and i want a restart option. how can i reload the form(Level)?
    (i can do it by object by object, but exist a diferent way?)
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: [VB6] - Reload a form

    This will unload the form...!
    Code:
    Unload Form1
    And this will show/load the Form:
    Code:
    Form1.show
    ...

    Or you can include those things that will be executed on starting the game inside a sub or function. Example:
    Code:
    Public Function StartGame()
    '// Load sprites
    '// Load Graphics
    '// Load configuration, etc.
    End Function
    And another for unloading:
    Code:
    Public Function EndGame()
    '// unLoad sprites
    '// unLoad Graphics
    '// unLoad configuration, etc.
    End Function
    So, when the user wants to restart the game, call EndGame and then call the StartGame....

    It's just a thought...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  5. #5
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: [VB6] - Reload a form

    I'm assuming you have all your code within secregated methods and not in your form events.

    Thus you should be able to simply re-call the methods which initialize your game-screen, your variables and objects.

    However, If you really must re-load the form you need to free the current form from memory first before you reload it:

    VB Code:
    1. Unload Form1
    2. Set Form1 = Nothing
    3. Load Form1
    4. Form1.Show

    If you do not set the actual form to nothing the Form_Initialize() event will not be triggered a consecutive time.

    If you are using a Form variable you still must set the actual form to nothing as well or you also get the problem of the Form_Initialize() event not firing again when reloading the form.

    The reason for this is that VB's Unload removes the form or control from memory but not the actual code page. The form's code page still resides in memory untill you set the actual Form1 object to nothing.
    Last edited by Optional; Feb 15th, 2010 at 07:12 PM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - Reload a form

    Quote Originally Posted by Optional View Post
    I'm assuming you have all your code within secregated methods and not in your form events.

    Thus you should be able to simply re-call the methods which initialize your game-screen, your variables and objects.

    However, If you really must re-load the form you need to free the current form from memory first before you reload it:

    VB Code:
    1. Unload Form1
    2. Set Form1 = Nothing
    3. Load Form1
    4. Form1.Show

    If you do not set the actual form to nothing the Form_Initialize() event will not be triggered a consecutive time.

    If you are using a Form variable you still must set the actual form to nothing as well or you also get the problem of the Form_Initialize() event not firing again when reloading the form.

    The reason for this is that VB's Unload removes the form or control from memory but not the actual code page. The form's code page still resides in memory untill you set the actual Form1 object to nothing.

    Edit: As usual akhileshbc, you beat me to it and as usual with a much clearer response
    in these case i can't use unload, because i can't unload the form that i'm using.
    but is slow, is like pause the program(in these case the game), then load the form.
    what you can tell me?

    akhileshbc, i like you sugestion, i build 1 similar situation. but instead work with every controls(it's a diferent way that i build a game), i wanted do these not so "complex"
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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