×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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!
  • Students Click Here

*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

Jobs

ComboBox problem
3

ComboBox problem

ComboBox problem

(OP)
Hi All,
I have a combobox in one of my forms that gets populated by an OCR process (so that part works, but want to give a full context of the issue).
Sometimes, the city doesn't get populated (lots of reasons for this), and it's blank. If I put a value into the combobox, I have a "VALID" snippet that checks to see if this is a known city (this is for purpose of establishing suburbs which are used in another area of the application as kind of a "grouping" of cities so on a map, for example, Vienna Virginia, and Washington DC will show up as the same high level point on the map. So that's what this is used for, but here is my problem.

If the field is blank, and I put a value in it, (let's say Montego Bay), which isn't found in the table, I want it to KEEP the value present in the field. I have this code in the VALID clause:

CODE

lcCurValue = This.DisplayValue
*
IF NOT EMPTY(ThisForm.txtState.Value) OR NOT EMPTY(ThisForm.cboCountry.Value)
	SELECT CTSITE
	SEEK UPPER(This.Value)+UPPER(ThisForm.txtState.Value)
*
	IF FOUND()
		ThisForm.cboCountry.Value = CTSITE.SITECOUNTRY
		ThisForm.txtRegion.Value = CTSITE.SITEREGIONBOUNDARY
	ELSE
		lnLaunchRegion = MESSAGEBOX("Region Not Defined, Do You Want to Define it Now?",52,"Region Not Defined")
		IF lnLaunchRegion = 6
			DO FORM CTSITE.SCX
		ELSE
			This.Value = lcCurValue
			This.DisplayValue = lcCurValue
			This.Parent.txtState.Value = ""
			REPLACE TTPARSEBC.CITY WITH This.Value
		ENDIF
	ENDIF
ENDIF 

The problem is, as soon as this snippet finishes, the display value is blank. Even though it gets assigned by keeping it with the lcCurValue. Is there something odd about the VALID event that I'm missing?
I even added the "REPLACE" clause in the temp table because I thought the control source was causing the "" value, but that didn't seem to fix it either.

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox problem

Scott,

I dont have any idea how to populate a combobox through an OCR process, for me there are 10 possibilities to do this Value, Alias, SQL etc, however OCR does not belong in this range. It seems to me your question is 'how do I allow to add a value which is not found to my combobox datasource?' Please read in this respect the FAQ's in this forum by Mike (McGagnon). If I am wrong with my assumption please report back here.

Regards,
Koen

RE: ComboBox problem

Scott,

Off-hand, I can't see anything wrong with your code. I've simulated what you are trying to achieve, and it seems to work for me.

The only problem I can see is that, in your SEEK, I think you need to wrap ALLTRIM() round the two values. But I'm not sure if that will solve your problem.

I also added this.Requery() after the REPLACE.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: ComboBox problem

(OP)
Hi Mike,
Sorry for the slow reply, I've had to play around with this a bit, and had a very long couple of days on other stuff.
So your comment gave me an idea, and I moved the code from the VALID to the LostFocus... and like magic, it works as expected. I'm not sure what about the VALID event is causing the problem (and I hate when I can't figure it out), but something odd happens between leaving the last line of valid, and returning to the next line of code, it just vanishes in between. But, with it on the LostFocus, it worked... so for now I'm happy with that.
Thanks for validating it, it at least gave me hope that it could be resolved somehow.
Cheers,
-S

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox problem

2
The main purposes of valid and lostfocus differ.

If you return .F. from valid, that means the value is not valid and focus stays.
Lostfocus happens when a control lost focus. It doesn't control anything, you can't prevent or stop the loss of focus, but it happens just before deactivate, so you might do something that's of importance before the deactivate happens - for whatever reasons.

The whole event order of a focus moving from control 1 to control2 is a bit different than many people think.

User presses TAB, that causes Valoid of the focused control. The whole cascade of events to come normally might be stopped here with a .F. returned. Valid has much more control and possibilities than to decide between yes or no, but that's another topic.

Once the valid allows the control to be left, in a typical case tab-order will determine which other control gets focus next, in case of TAB key, mouse click obviously determines the target control clicked on. Anyway, before lostfocus happens, whatever control is targetted first also has it's right to refuse to get focus in its When event. Only if control2's When agrees with control1's Valid, the control1.lostfocus happens and then the control2.Gotfocus. So tab or click on control1 causes these events:

control1.valid
control2.when
control1.lostfocus
control2.gotfocus

Moving code from control1.valid to control1.lostfocus changes the order of code execution in respect to control2.when, as control1.lostfocus happens after that. Even if there is no code in control2, the native behavior of control2 in respect of the When() event might have changed. It might be some neglectable seeming detail like the active workarea.

Aside from that TAB also causes a keypress event and a mouse click to move focus causes a click event, too, obviously. So the way of changing focus can also play a role.

Bye, Olaf.

RE: ComboBox problem

(OP)
Hi Olaf,
I did not know about the .F./.T. nature of Valid. Very interesting. I'm still not clear on what was causing the field to be blank after, but I can see there could be many things that are resulting in it if the Valid is false. The plus side is, the LostFocus does the trick, an I can avoid the Valid entanglement, but I can see how mastery of that will enable some interesting possibilities, so I'll keep that in mind. In any case, it's a star.
Cheers,
-S

Best Regards,
Scott
MIET, MASHRAE, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"Everything should be made as simple as possible, and no simpler."hammer

RE: ComboBox problem

There's a subtlety Olaf leaves out here.

After Valid() the control's value has not been written to the controlsource yet. In Lostfocus() it has.

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!

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