?
Solved

something about VB simple FORMS

Posted on 2000-04-14
22
Medium Priority
?
160 Views
Last Modified: 2010-05-02
i have a form which is heavy loaded with a lot of controls, some of them are graphics.
now, even when loading all in the back, before the form is displayed - only the SHOW or Visible=true - takes quite a lot of time to make the form displayed in its stable-final look (on my 366MHZ,128MB it takes about 1-2 seconds). as i said - it's a heavy one.
but that's not the problem....

the problem is that in a certain situation - i have to run a function just in the moment the form becomes stable and fully displayed. NOT BEFORE. NOT AFTER. then - hide the form.
as far as i know - there is no EVENT that fired on the moment the form becomes stable.
i've tried all traditional events (Activate, GotFocus, Resize, Paint) but all fired before all the form's controls are fully displayed.
MSDN does not mention that issue when dealing in "Life Cycle of Forms".

well ?
0
Comment
Question by:AnswerTheMan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
  • +6
22 Comments
 

Expert Comment

by:vbmitch
ID: 2718138
Try putting a timer in with a very small interval, 1 works well, make it something like this:

Sub Timer1_Timer ()
'Put functions here
Timer1.enabled = false 'So it only calls once
End Sub

Set the timer to enabled, and run the project. It should activate when you want it to.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2718143
how bout initialize event?
0
 
LVL 15

Expert Comment

by:ameba
ID: 2718185
use Activate event:

Option Explicit
Private initDone As Boolean

Private Sub Form_Activate()
    If Not initDone Then
        ' do something
        initDone = True
    End If
End Sub

If all the form's controls are not fully displayed, this means:
- you are using async operation (e.g. DataGrid, the solution is to use AsyncReadComplete event), or
- you have DoEvents statement in your code (remove it)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:wsh2
ID: 2718565
Use a module to perform your form load. Place a Sub Main procedure in it.. and change the Project properties to start the project there. In your sub main.. put the following:

Private Sub Main ()

   frmSplashScreen.Show ' eye candy

   Load frmLoadedWithControls
   Laod frmBeginningScreen

   frmSplashScreen.Hide ' All forms loaded.. no more eye candy

   frmLoadedWithControls.Show
   
   ' Once and done processing

   frmLoadedWithControls.Hide

   frmBeginningScreen.Show

End Sub
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2718569
Ameba:
I don't necessarily agree with using the Form Activate event.. but you are absolutley right on the mark with the (Ameba writes):

If all the form's controls are not fully displayed, this means:
- you are using async operation (e.g. DataGrid, the solution is to use AsyncReadComplete event), or
- you have DoEvents statement in your code (remove it)

Well keyed.. <smile>.

0
 
LVL 5

Author Comment

by:AnswerTheMan
ID: 2719376
BHHH.... a timer.... thanks but NO.
this app should do the job the moment the form is fully displaye on both 486 machine with 16 MB ram andd on P-3 600 machine with 256 mb ram.
would the suggested timer will provide what i'm after on both machins ? you know the answer.
0
 
LVL 5

Author Comment

by:AnswerTheMan
ID: 2719409
ameba :
there is no async operation whatsoever involved in loading the form's controls - nor DoEvents statement.

i've checked the Activate event in many ways, an i know FOR SURE that it is
fired BEFORE all controls are set and stable.




wsh2 :
since i wrote that all i need is to capture the moment everything is stable -
splash screen is not relevant to the question. it won't give me any indication for what i'm after.

0
 
LVL 14

Expert Comment

by:wsh2
ID: 2719416
Just put the splash screen there for eye candy.. (by the sounds of all that you are loading.. you need a bit if time). The Load statements should perform synchroniously (ie no disply).. as such.. the form should not show until the load is done. Give it a try.. <smile>.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2719470
just a thought but i have no idea of its validity; the controls collection from what I understand enumerates all the LOADED controls of the form.  therefore since you are the designer you are aware of the number of controls before the program is executed.  if what i believe about the collections is true can you just perform a check to see if the controls.count property matches the total number of controls that are on the form.  if i'm way off base here someone enlighten me as to the life cycle of the controls collections of a form.  or do i need to post my own question for that? =)
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2719742
If there was some reason given as to why this form only has to be displayed long enough for one function to run, we might be able to come up with a solution that didn't even require it to be displayed at all.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2720235
Foyal:
I am in complete agreement with you.. a form LOAD (without any display) should suffice to get everything properly  initialized and created. The questioner's need to display the form briefly and then immediately hide it.. is certainly a mystery to me as well.. <smile>.

Azra:
Forms and the Controls on them exist until the form is completely dereferenced AND unloaded.. <smile>.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 2720245
<sheesh>.. I just read my earlier  comment.. I really shouldn't drink coffee, eh?... <lol>. Getting my grammar book and resending:

I added the splash screen only to provide eye candy.. because it sounds like you have a lot of things to load before anything is dissplayed to the user. Yes it is superfulous to the question, I was only trying to be helpful if happens to be the situation (long initial load).

The LOAD statements given above will execute synchroniously.. (ie first stement executes completely before the next statement begins). As such.. your form will not appear until the Form.Load method is completed.. and then only when a Form.Show method is executed.

0
 
LVL 28

Expert Comment

by:Ark
ID: 2721407
What's about FirstInTabOrderControl_GotFocus?
Cheers
0
 
LVL 28

Expert Comment

by:Ark
ID: 2721411
or using Ctl.SetFocus for any control and start function from ctl_GotFocus event?
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2721578
Is this another version of the "need to capture the screen to save an error condition" question?
0
 
LVL 2

Expert Comment

by:JetScootr
ID: 2725157
One problem I have had, similar to this:  Referencing DAO data controls from the Form_Load event.  Sometimes it works, sometimes it don't.  Our solution was this:

Sub Form_Load()
Dim UselessWaste as control
For Each UselessWaste in Controls
    UselessWaste.Tag = UselessWaste.Tag
Next
Data1.Recordsource = OtherModules_Sql_Statement
Data1.Requery
end sub


Don't know if this exactly rings the bell for you - for us, it made sure every control was loaded enough for us to read & write  the tag property - then we didn't care what zorder that "Data1" was in - it was always loaded when we fired the requery.
 
0
 
LVL 5

Author Comment

by:AnswerTheMan
ID: 2727767
ok ppl. thank you all.
i've managed to get around it and in case you want to know how - here it is :
1
The goal of all that is to SHOW the user that a very complicated function he activated is being carried out.
although the mission can be carried out in the back - i've decided to make it
visual to the user in such a way that a FORM containg diffrent content will
be Show at the end of each LOOP-ROUND that filling its controls with diffrent data.
since the proccess is long - i wanted to hide that form in the moment it is stable in order not to spend time for nothing.
i did not wanted to do half work and hide the form before it's fully displayed.
that was the background for the question.
2
doing that i've find out that the ACTIVATE event that is the LAST event to be fired as a result of the SHOW command to the form - is fired before the form is completly displayed.
so i've had no indication for the moment the form is fully displayed, and did not know when to hide it.
3
since filling the form's controls and showing it is carried out from other form's code - i tried to capture the desired moment from there :
after the SHOW command i start a LOOP searching for the API GetWindowText , which gives the caption of the Window with the FOCUS.
i've found that it gives the Desired form's caption ONLY WHEN IT'S FULLY DISPLAYED, and here i've nailed the moment. sure i had to add a DoEvents
statment to that loop to enable the form to complete the show operation.
4.
that's works fine on both fast and slow machines.
5.
thanks all again
0
 
LVL 5

Author Comment

by:AnswerTheMan
ID: 2727786
Foyal : don't understand you last comment
0
 
LVL 3

Expert Comment

by:Foyal
ID: 2728259
There was a question posted recently where someone wanted to capture the screen if the form loaded in an error condition so as to save a picture of the screen. To me, it made a lot more sense to trap the error and do something about it. But then, without adequate information it's very hard to make judgements. I guess there must be a reason; like I said, it's hard to tell sometimes.
0
 
LVL 28

Expert Comment

by:Ark
ID: 2728738
AnswerTheMan,
your trick is interesting. BTW, one thought, did you try Me.Refresh method at the end of form_load event. This method force repainting form and you can use form_activate event after this. I tried it on form with 93 controls - it works.
Cheers
0
 
LVL 5

Expert Comment

by:ianB
ID: 2741488
Community Support has reduced points from 200 to 0
0
 
LVL 5

Accepted Solution

by:
ianB earned 0 total points
ID: 2741489
Refunding points and moving to PAQ list.

Ian
Community Support @ Experts Exchange
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question