MMCC MASTHEAD


INDEX

v1.10
Mid-Michigan Computer Consultants, Inc.
509 Center
Bay City, Michigan

Sales (989) 892-9242             Support (989) 686-8860


ANSI Standard PL/B Language
FOCUS and VALIDATE
Updated Dec 15, 2001

FOCUS
FOCUS is a term used to indicate which object on a screen is currently active. If you click on a name field, that field "has the focus" until you click on something else.

Some confusion occurs concerning how and when to use focus events. Two events are generated regarding FOCUS:
  • GOTFOCUS occurs when an object obtains focus. You can take an action at that time such as displaying a prompt or changing a color or changing other objects on the screen.

  • LOSTFOCUS occurs when some other object is given the focus. In other words, the user has left the field which previously had the focus. You can use this event to edit the field which the user just left and indicate errors.

GOTCHA's
The instinctive thought by most programmers is that LOSTFOCUS is the perfect time to check an object for errors. If the user clicks on SEX and enters "N", you'd want to check that and throw an error alert immediately.

The subtle problem is that when a user clicks another object Windows gives you the GOTFOCUS event on the new object BEFORE giving LOSTFOCUS for the previous object.

The difficulty, of course, is figuring out where you came from when you land on a new object. One method is to set some kind of flag to indicate where you currently are (GOTFOCUS) and then test that first on the NEXT GOTFOCUS. In pseudo code:
   GOTFOCUS event on STATE
     If I was last on NAME
         edit the name
     Else if I was last on SEX
         edit the sex
     endif
     save "STATE" as last event
     return
	 
   LOSTFOCUS event... 
     just ignore it since
     you do everything on
     the GOTFOCUS
Obviously, the above code can get rather involved if you have lots of objects on the screen. It's not a good solution.
VALIDATE
Recognizing the difficulties, Sunbelt added the psuedo event "VALIDATE" to their PL/B just for this:
  • The VALIDATE event is controlled by the run-time code and handles the necessary juggling of events. When a person leaves one object and goes to another, the VALIDATE event fires FIRST for the object which just lost the focus. You can reliably edit the data on an object's VALIDATE event and not worry about FOCUS.

NOTE: Validate is not completely automatic. Each object has a new, related property called CAUSE VALIDATE which controls validation. The idea behind CAUSE VALIDATE is this.
  • The validation is triggered by the GOTFOCUS on the next object. The run-time is going to slip in first and give your program a VALIDATE event on the field which just lost focus.

    Sometimes you may NOT want this to happen. For example, if the user clicks a CANCEL button, you don't need (or want) to validate the field they just left. To accomplish this, you set the CANCEL button's CAUSE VALIDATION property to OFF.

Being aware of CAUSE VALIDATE is important because the form designer defaults objects with this property turned OFF. If you have a VALIDATE event on any objects, be sure to insure that CAUSE VALIDATION is turn on for all other objects which you'd want to have it for.

INDEX

v1.10
Send e-mail to MMCC.

Write to MMCC Technical Support at:
MMCC, Inc.
600 W. Midland
Bay City, MI 48708
(989) 686-8860
| Home   |

© 1997 MMCC, Inc. All Rights Reserved.

Report problems or suggestions to support@mmcctech.com
Since 09/15/1998