Form validation - sequence of events

Filip Van Wynsberghe

Member
Licensed User
Longtime User
Hi,

I'm new to basic4ppc and I'm writing my first application.

I have a fom with some textboxes and I'm writing a validation routine on the 'lostfocus' event of the first textbox. It looks to me that the next control (also a textbox) gets the focus before my validation routine has ended. It looks even to me that the validation routine is interupted to execute the code on the getfocus of the next textbox.

Is this correct?

Also, in my validation routine, when the input is invalid, I'm sending a msgbox, with as result that the lostfocus event of the 2nd textbox gets fired too.

Running this in debug mode (step by step) to find out the sequence of the events, does not seem that easy, because (obviously) the gotfocus/lostfocus events happen at every step...:BangHead:

I could add some tests in my code to get rid of my problems but I wonder :
- if this is good practice to write a validation routine on the lostfocus event?
- if there exist some guidelines with 'best practices' including some do's and don'ts?
- if I should (always ?) use the formlib library and use other events? Which ones?

Many thanks for your help.
 

mjcoon

Well-Known Member
Licensed User
As you have discovered, it is virtually impossible to debug event code, especially focus-related, under the IDE. But given that caveat, using focus events seems a good way of validating entries rather than waiting until the "OK" for the whole form.

I don't believe that (in "live" running) you will get an event for a get focus while dealing with the previous focus event.

It is less surprising that a MsgBox call will result in a lost focus event.

It is often the case that a boolean flag must be switched to show the context and distinguish between events that result from the sort of user action that is of interest, and those that are the consequence of program action (like the MsgBox(), or setting the initial focus).

You may get further/better advice from the experts...

Mike.
 
Top