Results 1 to 13 of 13

Thread: [RESOLVED] Form remains visible after it has been unloaded

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Resolved [RESOLVED] Form remains visible after it has been unloaded

    I have this code for a menu in my main form:
    VB Code:
    1. Private Sub mnuProcessData_Click()
    2.     'Load a from where some math calculations
    3.     'are performed on a large array of data
    4.     frmDataProcess.Show 1
    5.     'After the processing, the processed data
    6.     'which were plotted on a picturebox must
    7.     'be replotted as they have changed
    8.     UpdateEverything
    9. End Sub
    In frmDataProcess is a 'Close' command button which unloads the form so control is returned to the main form and sub UpdateEverything which is fairly time-consuming takes over.
    It works well, but after I click on 'Close', frmDatProcess remains visible for awhile, which I don't like. Any ideas to avoid this?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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

    Re: Form remains visible after it has been unloaded

    If your routine is taking a while to complete, then maybe through in a DoEvents to let the OS finish closing the form.

    Just a guess.

  3. #3
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Form remains visible after it has been unloaded

    Maybe a 'DoEvents' may help....

  4. #4

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Form remains visible after it has been unloaded

    It didn't, but the thing is sub UpdateEverything is calling various other subs which in turn call other subs which... and I have yet to find out which ones have the most time-consuming loops.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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

    Re: Form remains visible after it has been unloaded

    Would hiding it work better?

  6. #6

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Form remains visible after it has been unloaded

    Quote Originally Posted by Hack
    Would hiding it work better?
    Nope.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  7. #7
    Lively Member RickyOswaldIOW's Avatar
    Join Date
    Sep 2007
    Location
    Ryde, Isle of Wight
    Posts
    120

    Re: Form remains visible after it has been unloaded

    You could try putting frmDataProcess.Show 1 AFTER UpdateEverything. This may mean the form will take a while to show up though as UpdateEverything will have to execute. Maybe the problem is on frmDataProcess itself?

  8. #8

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Form remains visible after it has been unloaded

    Quote Originally Posted by RickyOswaldIOW
    You could try putting frmDataProcess.Show 1 AFTER UpdateEverything. This may mean the form will take a while to show up though as UpdateEverything will have to execute. Maybe the problem is on frmDataProcess itself?
    UpdateEverything must be called AFTER frmDataProcess has been loaded and used to modify the data. Otherwise there's nothing to update.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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

    Re: Form remains visible after it has been unloaded

    Well, we are kind of running out of ideas here, so I guess I will go back to the original question.

    How long does it stay visible and what kind of impact does this have?

  10. #10
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Form remains visible after it has been unloaded

    Add DoEvents before calling UpdateEverything.

    Code:
    Private Sub mnuProcessData_Click()
        'Load a from where some math calculations
        'are performed on a large array of data
        frmDataProcess.Show 1
        DoEvents
        'After the processing, the processed data
        'which were plotted on a picturebox must
        'be replotted as they have changed
        UpdateEverything
    End Sub

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

    Re: Form remains visible after it has been unloaded

    That has already been suggested and apparently, didn't work.

  12. #12
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Form remains visible after it has been unloaded

    I know, but you didn't mention where to add it.

  13. #13

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Form remains visible after it has been unloaded

    Quote Originally Posted by anhn
    Add DoEvents before calling UpdateEverything.

    Code:
    Private Sub mnuProcessData_Click()
        'Load a from where some math calculations
        'are performed on a large array of data
        frmDataProcess.Show 1
        DoEvents
        'After the processing, the processed data
        'which were plotted on a picturebox must
        'be replotted as they have changed
        UpdateEverything
    End Sub
    It worked! What happened was I placed the DoEvents statement in the wrong place, i.e. not where you've suggested but inside UpdateEverything.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

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