Strange control event behaviour 
Author Message
 Strange control event behaviour

Hi,
I am experiencing some very strange happenings in VB5 (service pack 3) apps
running under Windows 95 and Windows NT (service pack 3).  The application
are form based apps capturing data into DAO databases.  Everything works
fine when run in the development environment but things get seriously
erratic when the executable is run (compiled to native code).

When tabbing from one text box to another, the GotFocus event of the control
I am tabbing into occurs before the LostFocus event of the control I am
tabbing out of.  Also MSMask controls seem to fire their GotFocus events
twice in succession when I tab into them.  I have tried numerous DoEvents
and even API Sleeps to try and resolve this but no joy.

Could the problem lie in the fact that I am launching many message boxes
from the focus events of my controls?

Please - any input appreciated here folks.

Regards,

Fergal Moran....



Sat, 06 Jan 2001 03:00:00 GMT  
 Strange control event behaviour



Quote:
> Hi,
> I am experiencing some very strange happenings in VB5 (service pack 3)
apps
> running under Windows 95 and Windows NT (service pack 3).  The
application
> are form based apps capturing data into DAO databases.  Everything works
> fine when run in the development environment but things get seriously
> erratic when the executable is run (compiled to native code).

> When tabbing from one text box to another, the GotFocus event of the
control
> I am tabbing into occurs before the LostFocus event of the control I am
> tabbing out of.

That's normal and expected.  You can't lose focus until someone else has
got it.

Quote:
> Also MSMask controls seem to fire their GotFocus events
> twice in succession when I tab into them.  I have tried numerous DoEvents
> and even API Sleeps to try and resolve this but no joy.

I never use 'em, so I can't comment.

Quote:
> Could the problem lie in the fact that I am launching many message boxes
> from the focus events of my controls?

Yep: that could be a problem.  Messageboxes mess up the event sequence
sometimes, especially with regard to focus events.

Jim Deutch
MS Dev MVP



Sat, 06 Jan 2001 03:00:00 GMT  
 Strange control event behaviour

Quote:
>> When tabbing from one text box to another, the GotFocus event of the
>control
>> I am tabbing into occurs before the LostFocus event of the control I am
>> tabbing out of.

>That's normal and expected.  You can't lose focus until someone else has
>got it.

Well - maybe but would it not also be true to say that you can't get focus
until someone loses it.  Chicken and Egg syndrome here.  It seems to happen
one way around in the development environment and the other way around in
the executable.


Sat, 06 Jan 2001 03:00:00 GMT  
 Strange control event behaviour


Quote:
>>> When tabbing from one text box to another, the GotFocus event of the
>>control
>>> I am tabbing into occurs before the LostFocus event of the control I am
>>> tabbing out of.

>>That's normal and expected.  You can't lose focus until someone else has
>>got it.

>Well - maybe but would it not also be true to say that you can't get focus
>until someone loses it.  Chicken and Egg syndrome here.  It seems to happen
>one way around in the development environment and the other way around in
>the executable.

I have heard several times that Focus events are a bit too unpredictable for
this kind of use - from my experience, I would have to agree.

It sounds to me like you are doing validation in LostFocus events.  In
general, users tend to get upset if message boxes pop up all the time when
they tab between controls.  It's a whole other area of discussion, but maybe
you could think of other ways of indicating invalid data?  Something like
changing the background colour of invalid controls, and disabling the OK
button...

    - Paul



Mon, 08 Jan 2001 03:00:00 GMT  
 Strange control event behaviour

Quote:


<snip>

> It sounds to me like you are doing validation in LostFocus events.  In
> general, users tend to get upset if message boxes pop up all the time when
> they tab between controls.  It's a whole other area of discussion, but maybe
> you could think of other ways of indicating invalid data?  Something like
> changing the background colour of invalid controls, and disabling the OK
> button...

>     - Paul

Amen! MsgBoxes are annoying and overused.
Dave

--
I am a resident of Washington state. In Washington, Spam
is subject to a $500 or greater penalty. You are warned.



Mon, 08 Jan 2001 03:00:00 GMT  
 Strange control event behaviour
I believe one effect of the message box wherever it occurs is to lose any
waiting events. This is why debug.print is usually the only way to see
what's going on in focus and window activation events.

Bertie
PS I try to avoid using LostFocus for anything other than cosmetic purposes.
I try to do all validation at form level rather than between controls. VB6
introduces a whole new validation model which should render LostFocus
obsolete as a home for validation.


Quote:
>Does displaying message boxes cause problems if they are called in a
function
>called by the LOSTFOCUS procedure?
>snip<



Sat, 13 Jan 2001 03:00:00 GMT  
 Strange control event behaviour

Quote:

> I believe one effect of the message box wherever it occurs is to lose any
> waiting events.

I experienced that any event looses all other waiting events as soon as
a Msgbox appears _in the programming environment_.

In the _compiled EXE-Version_ however, the situation is as follows:
an event starts
(other event(s) waiting)
a message box appears
-> in the meantime (as long as the user doesn't press OK) the waiting
events are being executed!



Mon, 12 Feb 2001 03:00:00 GMT  
 Strange control event behaviour

Quote:


>> I believe one effect of the message box wherever it occurs is to lose any
>> waiting events.

>I experienced that any event looses all other waiting events as soon as
>a Msgbox appears _in the programming environment_.

>In the _compiled EXE-Version_ however, the situation is as follows:
>an event starts
>(other event(s) waiting)
>a message box appears
>-> in the meantime (as long as the user doesn't press OK) the waiting
>events are being executed!

Thanks for that, Tom. I think you are correct. I believe this behaviour
could vary depending on the platform (3.11, 95/98, NT) as well. Does anyone
have the full deal?

Bertie
PS Sorry about the US-style jargon there but it just kinda fitted I guess...



Mon, 12 Feb 2001 03:00:00 GMT  
 Strange control event behaviour
I'm not sure what I just read but I believe that the DoEvents keyword can
help.


Mon, 12 Feb 2001 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Strange control event behaviour

2. Strange behaviour of AfterUpdate event

3. Strange behaviour in the KeyDown event

4. DT Picker Control on Multi Page - Strange Behaviour

5. strange data control behaviour with DAO 3.6 and SQL server

6. Strange RichText Control Behaviour

7. Timer Control - strange behaviour

8. Strange behaviour on common controls, HELP !!!!!!

9. Strange behaviour with array of Winsock controls

10. Strange behaviour on common controls, HELP !!!!!!

11. Strange behaviour on common controls, HELP !!!!!!

12. MFC Control Events Caught in VB Program - Weird Behaviour

 

 
Powered by phpBB® Forum Software