Solved

something about VB simple FORMS

Posted on 2000-04-14
22
152 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
  • 5
  • 4
  • 3
  • +6
22 Comments
 

Expert Comment

by:vbmitch
Comment Utility
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
Comment Utility
how bout initialize event?
0
 
LVL 15

Expert Comment

by:ameba
Comment Utility
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
 
LVL 14

Expert Comment

by:wsh2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 14

Expert Comment

by:wsh2
Comment Utility
<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 27

Expert Comment

by:Ark
Comment Utility
What's about FirstInTabOrderControl_GotFocus?
Cheers
0
 
LVL 27

Expert Comment

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

Expert Comment

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

Expert Comment

by:JetScootr
Comment Utility
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
Comment Utility
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
Comment Utility
Foyal : don't understand you last comment
0
 
LVL 3

Expert Comment

by:Foyal
Comment Utility
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 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
Community Support has reduced points from 200 to 0
0
 
LVL 5

Accepted Solution

by:
ianB earned 0 total points
Comment Utility
Refunding points and moving to PAQ list.

Ian
Community Support @ Experts Exchange
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now