AndrewMozley
Programmer
Many forms have a textbox control for data entry. And such a control will very likely have a Valid() method to keep focus on the control until an acceptable value is entered. So, for a very simple example, if txtcustRef must be at least 4 characters, one might include code like :
Code:
* MycustRef.valid()
IF LEN(This.value) < 4
MESSAGEBOX(“The reference must be at least 4 characters”)
RETURN .F.
ENDIF
RETURN DODEFAULT()
There will be circumstances in which you do not want the validation – for example if a ‘Cancel’ button is provided on the form and the user clicks on that. So txtcustRef.valid() may well include code to handle that.
But there are other circumstances in which you might not want the validation code be be invoked. For example there might be a Customer enquiry form where the user can look at old invoices and see what reference was used last time. In that case, if the user clicks on the enquiry form you might not want to validate the customer reference. That might be handled by detecting the position of the mouse on another form, and once again the Valid() method could invoke code to detect the position of the mouse, perhaps using the SYS(1270) function.
But here again a complication arises : if this other enquiry form (or any other form) is open, and the user has let the mouse wander over this other form - without clicking – we would not want to inhibit the validation (which checks for a long enough reference).
So I included code in txtcustRef.valid() to say that if LASTKEY() was <Tab> or Enter<>, then do the validation anyway, but otherwise do the check to bypass validation if the mouse is on another form.
This works up to a point. But if the user has navigated to txtCustRef by pressing <Enter> (from the previous textbox and then clicks on the other enquiry form, txtcustRef.valid() will think “LASTKEY() was <Enter>” (even though that was not what invoked this call to txtCustRef.valid ); and it will therefore decide to do its validation, and complain about the reference being too short – which is not what was wanted in this case.
I feel I am going round in circles !!
I did see a thread on techtips from andreateh in Feb 2004 (search for CLEAR LASTKEY(). I wonder whether that might be relevant. Thanks in advance for your guidance.