×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

LostFocus not executing code

LostFocus not executing code

LostFocus not executing code

(OP)
Hello colleagues!

In my form I have 2 fields to receive data from user:

When the user completed typing in the first field, the application test if the second field is blank. If the second field is blank, it copies the contents from the first field to the socond field.

So I put the following code in the LostFocus event of the first field:

CODE -->

Object: txtLocalizador     Procedure: (event) LostFocus
IF SUBSTR(thisform.txtVoucher.Value,1,3)=SPACE(3)
	thisform.txtVoucher.Value=thisform.txtLocalizador.Value
ENDIF 

It works fine, if the user press Enter after typing data in the first field. If the user press TAB (instead of Enter) the second field is not populated with the data from the first field.

When we press TAB to go out from a field, it has not to execute the LostFocus event?

Thank you,
SitesMasstec

RE: LostFocus not executing code

Why are you testing if the first leading 3 characters are space characters?
It looks like this is the element that isn't executing properly to me.
Have you Set Step On at the lost focus event on the first field to trace what's happening?

Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate."

RE: LostFocus not executing code

The event happens, but if thisform.txtVoucher.Value is empty, you don't get SPACE(3) you get the empty string ''.

SUBSTR() is not padding the result to 3 characters just because you say you want 3 characters.

Chriss

RE: LostFocus not executing code

(OP)
Oh, I am getting old.

Yes, Cris, I added: OR thisform.txtVoucher.Value="" and now it works:

CODE -->

IF SUBSTR(thisform.txtVoucher.Value,1,3)=SPACE(3) OR thisform.txtVoucher.Value=""
	thisform.txtVoucher.Value=thisform.txtLocalizador.Value
ENDIF 

Thank you,
SitesMasstec

RE: LostFocus not executing code

Good to see you have a solution. However, a better way to test for an empty string would be to use the EMPTY() function. That avoids any issues with leading or trailing spaces (or TABs), and also avoids possible confusion caused by SET EXACT.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: LostFocus not executing code

Why do you even check the first three characters?
Why don't you use LEFT(thisform.txtVoucher.Value,3) for that? (It will also be a maximum of 3 characters, not exactly 3)
Why do you now only check the special empty case? If the other textbox would contain 2 spaces you would still not copy over the entered text.
Why don't you use THIS.VALUE inside the txtLocalizador textbox and instead use the long object name rooted in thisform?
There are several things I donÄt understand, but I would not necessarily change to using EMPTY, if there's a specific reason.

For example, you would also overwrite the value of thisform.txtVoucher.Value, if it starts with 3 spaces, but then contains text, for example ' test' would be "empty" in your definition of checking specifically the first 3 characters. Is this just overcomplicated thinking, like not using THIS when it's available, or is there some reason behind that?

Chriss

RE: LostFocus not executing code

(OP)
Yes Mike, it worked also. I changed the code to:

CODE -->

IF EMPTY(thisform.txtVoucher.Value)
	thisform.txtVoucher.Value=thisform.txtLocalizador.Value
ENDIF 

Thank you,
SitesMasstec

RE: LostFocus not executing code

(OP)
Chris, thank you for those nice tips, too.

Of course, if the txtLocalizador is " 45678" for example, it would be as it had nothing, because I just tested the first 3 characters, in my former code.

I also took note of your other tips. Indeed I was used to SUBSTR, explicitly code (thisform.txtLocalizador.Value instead of THIS.Value)

Thank you,
SitesMasstec

RE: LostFocus not executing code

You could also use ALLTRIM() before testing.

Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS, ATD

"I try to be nice, but sometimes my mouth doesn't cooperate."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close