By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,590 Members | 663 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,590 IT Pros & Developers. It's quick & easy.

Can i capture form level events in app. level in VB 6.0 in desktop application?

P: 9
I'm new to VB 6.0 as I'm a C# developer originally. I'm working on an application with hundreds of forms spread across multiple projects. Can any VB expert please guide me if there is a way of capturing form-level events at the application level at a common place so that my efforts are reduced? Otherwise, I'll have to make changes at the form level which will be quite cumbersome due to large no. of forms. I need to catch events to keep track of the time for which each form was in active state.
Sep 25 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
There may be much better ways, but one fairly simple approach would be to copy some standard code into each form which invokes your "application-level" procedure, perhaps passing the form itself (or just its name) as a parameter.
Sep 26 '07 #2

P: 9
There may be much better ways, but one fairly simple approach would be to copy some standard code into each form which invokes your "application-level" procedure, perhaps passing the form itself (or just its name) as a parameter.
So, you mean to say i can pass form name and access the form events at the application level using that passed form name.Are you sure i can capture those events there ?. I'm new to VB.So,a simple code sample regd. how to capture form events from the passed form name would be highly appreciated .I'm working on VB 6.0.Or else,Plz let me know the Property name to use to get the Form object and then events out of it.
Sep 26 '07 #3

Expert 5K+
P: 8,434
So, you mean to say i can pass form name and access the form events at the application level using that passed form name.Are you sure i can capture those events there ?
What I meant was you capture the events the same way as usual, by coding an event procedure in each form. But in each one, you just call a standard routine to do whatever it is you want to do at that point.

For example, in every form you could code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Click()
  2.   Do_Your_Application_Wide_Click_Event Me
  3. End Sub
This would trigger when that form is clicked, but all it would do is invoke the one standard routine, the same as all the other forms. If you pass the form as a parameter (as I've done here) then the standard routine can do whatever it wants with the form.

Don't forget, if you create Public variables within a form, you can treat it like a property of the form. That could be very useful for things such as tracking how long the form is loaded for. As an example of something like this, try creating Public TimeLoaded As Double in a form. In the Form_Load event (perhaps through a standard routine as described above) you could set the TimeLoaded variable to the current system time. In the Form_Unload event (again, could be in a standard routine that each form invokes) you can determine how long that form was loaded by subtracting <FormName>.TimeLoaded from the current time.

I hope this gets across the idea. As I said, there may be better ways to go about it. This is just what came to mind.
Sep 26 '07 #4

P: 9
What I meant was you capture the events the same way as usual, by coding an event procedure in each form. But in each one, you just call a standard routine to do whatever it is you want to do at that point.

For example, in every form you could code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Click()
  2.   Do_Your_Application_Wide_Click_Event Me
  3. End Sub
This would trigger when that form is clicked, but all it would do is invoke the one standard routine, the same as all the other forms. If you pass the form as a parameter (as I've done here) then the standard routine can do whatever it wants with the form.

Don't forget, if you create Public variables within a form, you can treat it like a property of the form. That could be very useful for things such as tracking how long the form is loaded for. As an example of something like this, try creating Public TimeLoaded As Double in a form. In the Form_Load event (perhaps through a standard routine as described above) you could set the TimeLoaded variable to the current system time. In the Form_Unload event (again, could be in a standard routine that each form invokes) you can determine how long that form was loaded by subtracting <FormName>.TimeLoaded from the current time.

I hope this gets across the idea. As I said, there may be better ways to go about it. This is just what came to mind.
Gotcha!. I 'm moving ahead in a similar fashion except that i don't need to track for time by myself.We have an API doing that already.I was interested in a way of catching events at a global level in the application identified with the Form.Seems like it is not possible with VB 6.0.Let me know if you get something on this in future.Its interesting.Thanks for all your effort.
Sep 26 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.