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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how determine current object 1

Status
Not open for further replies.

johncook

Programmer
Nov 24, 2002
154
US
It never ceases to amaze me how the things i want to do seem so simple and common yet so difficult to find the answer. i searched the FAQ's and 3 books.

Simple form, 2 text boxes and a command button.
User is in one of the text boxes. user presses command button. i want to determine which text box user was in so i can change the value in that textbox.

It would seem and if not for this, i will surely need to know, how to determine the "current object" (which textbox was the user in when they pressed the command button?).

Thanks,
John
 
John:

Since the commandbutton would become the ACTIVECONTROL when you pressed it, you would need to create a form property, namely THISFORM.LASTCONT, and in the GOTFOCUS event of the textboxes, enter THISFORM.LASTCOUNT = THIS.

When you press the commandbutton, refer to the value of THISFORM.LASTCONT (it will be an object "O" type) to determine the last textbox accessed.

Good luck!

Al
 
John:

Typo:

Since the commandbutton would become the ACTIVECONTROL when you pressed it, you would need to create a form property, namely THISFORM.LASTCONT, and in the GOTFOCUS event of the textboxes, enter THISFORM.LASTCOUNT = THIS.

(remove red U)

Al
 
Allan,
To your 2nd reply, I had decided while I was waiting on a reply, to do just that all the time believing someone would later tell me "why not just ask for current object from the system?" Thanks again,
John
 
John,
Note: While Al is correct, you'll need to use or save off that value in the Command Button's When() method. After the When(), the Active control is either undefined (e.g. GotFocus()) or it will be the button itself (e.g. Click())!

Rick
 
Rick:

If John only enters code (THISFORM.LASTCOUNT = THIS) in the GOTFOCUS events for the textboxes he needs to monitor, I think he'll be OK.

Agree?


John:

You probably figured this already, but reference THISFORM.LASTCONT.NAME in your commandbutton.click event.

Al
 
John/Rick:

Should have mentioned this before. In the commandbutton's click event:

IF TYPE("THISFORM.LASTCONT") = "O"

* act on THISFORM.LASTCONT here, in case user presses
* this button before selecting any textbox

ENDIF

Al
 
Al,
When I started writing my response, only your first message was showing in my browser, and so I was expanding on that response. Yes, having each text box use your code (or better your textbox base class), will work, but if only the one command button requires this info, it's more overhead than may be needed. The advantage of my code is that it works for ANY type control on the form and it requires changes in just one spot.

That being said, VFP gives us many ways to solve a problem so we don't have to do it the "right" way. :)

Rick
 
Thanks for all the assistance. Ok, I got that part working. Now I can't get it to refresh.

ThisForm.PRD_NO1.Value = (ThisForm.PRD_NO1.Value + ALLTRIM(this.Caption))
WAIT ThisForm.PRD_NO1.Value window
ThisForm.PRD_NO1.refresh()

Caption on command button is "1". The wait window shows "1"1st click, then "11" 2nd click, then "111" 3rd click, etc but value is not displayed in textbox. I imagine has to do with fact that textbox's control source is a file.field?
 
John:

What is the initial value (and type) of ThisForm.PRD_NO1.Value. Is its CONTROLSOURCE a character field, which it needs to be for you to concatenate (as you're doing)?

If it's numeric and you're trying to "add" the numeric value of the commandbutton's CAPTION, then you need to use:

ThisForm.PRD_NO1.Value = ThisForm.PRD_NO1.Value + VAL(This.caption)

The field will then update accordingly (ControlSource).


Al
 
Al I told you wrong. There is no control source. I am not getting any errors. I don't believe it is having a problem with an conversions. It just will not place the value in the textbox.
Thanks
 
John:

Please advise of what you're attempting. It appears you're trying to increment the value contained in the textbox by the value of the commandbutton's caption.

I'm assuming ThisForm.PRD_NO1 is the proper reference (NAME) to that text box.

If you're employing the mechanics of your original question, there may be an error in referencing that textbox from the form property, so it's not changing values.

Also, instead of ThisForm.PRD_NO1.Refresh(), try THISFORM.REFRESH().

al

 
Al,
This is a toucscreen app.
Instead of typing (no keyboard), user enters value by pressing command buttons, captions "1" thru "0". I am trying to have the user press the button in which case the caption is appended to the textbox's value. ALL characters, no numeric computations. The captions can be "A", etc as well.
Thanks
 
John, what are the textbox's FORMAT and INPUTMASK properties, if any?

Also, add a dummy textbox similar to the one that won't update, and reference that control from the commandbutton instead. Do NOT do a COPY from the one that doesn't update.

Al
 
Al,
Format is default (NONE).
Input mask is "XXXXXXXXXXXXXXX"
I will try the dummy textbox
 
Al, You were getting there. I removed the input mask and works perfectly. It may take me an hour to figure out why but I will probably just jot it down and something to do between 3 and 4 AM when I have nothing else to do. Thanks for all your assistance,
John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top