Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop LostFocus() from triggering the Valid() again 1

Status
Not open for further replies.

Rajesh Karunakaran

Programmer
Sep 29, 2016
535
0
16
MU
Dear Team!

I have a few validations in the VALID() event of a TextBox. Inside that, for one of the validations, I am showing a Messagebox for an alert. In the LOSTFOCUS() of the control I have some REFRESHs for 3-4 other controls and a SETFOCUS() to another control.

Now, after the LOSTFOCUS() it again goes to the VALID(). While that may be a VFP feature, the problem is I am getting that MessageBox twice. How can I avoid that? Or in other words, can I prevent LOSTFOCUS() from triggering the VALID() once again?

Thanks in advance.
Rajesh
 
The first time you show the messagebox, set a variable to .t. and next time it fires the same subroutine only display the message - or complete the lostfocus action - if that variable is .f.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Hi GriffMG

Thank you for your inputs. However, I believe there must be some straight way in VFP rather than controlling it through variables which makes it unnecessarily complex.

By the way, in fact, I managed to solve this problem by transferring my mentioned validation from VALID into LOSTFOCUS. Even now, when I issue a SETFOCUS from within LOSTFOCUS to any other control, it must be executing the VALID once again but the MessageBox won't be shown as that portion of code is not there in the VALID method.

I would still like to know if there is any way to avoid triggering Valid() from LostFocus() when we issue a SetFocus() in it.
I know the NODEFAULT can be used to bypass the default actions of events. But, in this case, it doesn't seem to work.

Any other way, tricks or VFP native way?

Thank you all once again,
Rajesh
 
Rajesh,

I think you were making the whole thing more difficult than it need be. On the surface, there doesn't appear to be any reason to use both the Valid and the LosfFocus for the same control. You were right to do away with the Valid completely, and put all your processing in the LostFocus.

Another option would be to put all the processing in the Valid, but to use the RETURN command to specify which control you want to move the focus to. If the validation fails, you would return .F. If it succeeds, you would return the name of the control to which you wish to move focus. (See the Help for Valid for more details.)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,
Hope you keep fine.

I don't have the same code both in Valid and LostFocus. I had the validations in Valid and the I use LostFocus to set the focus to the control I want. I didn't do away with Valid completely. Some code is there. But I moved the section of a validation which has a MessageBox to the LostFocus method.

I wrote the SetFocus in LostFocus because I can't use SetFocus in a Valid().
I didn't try using RETURN with object name in the Valid for this case.

Thank you very much for these suggestions.
Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top