[RESOLVED] Form remains visible after it has been unloaded
I have this code for a menu in my main form:
VB Code:
Private Sub mnuProcessData_Click()
'Load a from where some math calculations
'are performed on a large array of data
frmDataProcess.Show 1
'After the processing, the processed data
'which were plotted on a picturebox must
'be replotted as they have changed
UpdateEverything
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?
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.
Re: Form remains visible after it has been unloaded
Maybe a 'DoEvents' may help....
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.
Re: Form remains visible after it has been unloaded
Would hiding it work better?
Re: Form remains visible after it has been unloaded
Quote:
Originally Posted by Hack
Would hiding it work better?
Nope.
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?
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.
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?
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
Re: Form remains visible after it has been unloaded
That has already been suggested and apparently, didn't work.
Re: Form remains visible after it has been unloaded
I know, but you didn't mention where to add it.
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! :thumb: What happened was I placed the DoEvents statement in the wrong place, i.e. not where you've suggested but inside UpdateEverything.