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

How to find the current value of a textbox in the KeyPress event? 1

Status
Not open for further replies.

pctest

Programmer
Apr 12, 2004
89
US
I'm using VFP 8 SP1.

I want to able to find the current value of a textbox in the KeyPress event. For example, if the textbox has "AB" already and then I enter "C", I want to able to tell that "C" will be the new value of the textbox in the KeyPress event. Another example, if the texbox has -45 already and then I enter 63, I want to able to tell that 6 will be the new value of the textbox in the KeyPress event and then 63 will be the new value when I press "3" to enter the "3" of the "63".

Thank you for any help.
 
It's not foolproof, but it will give you the basic concept you need to complete this task...in the keypress event put the following:
Code:
LOCAL lcValue
lcValue = this.value
IF this.SelLength > 0
	lcValue = STUFF(lcValue, this.SelStart, this.SelLength,"")
ENDIF
lcValue = ALLTRIM(lcValue) + CHR(nKeycode)
wait window lcValue nowait && just for testing purposes

boyd.gif

craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Craig,

It works if the existing value are selected.

It won't work for the following scenarios:

If I have the number -45 and then type 6 when -45 are not selected, on the screen you will see 6 -4 and the lcValue is -456. If I enter now, 6 will be in the textbox.

If I have the number -45 and then type 6 after the minus sign when -45 are not selected, on the screen you will see -64 and the lcValue is -456. If I enter now, 6 will be in the textbox.


Thank you for your help.
 
Craig,

For the 2nd scenario, the end result is -6 not 6.
 
Hi Pctest

In the keypress event...
************************
DODEFAULT()
cNewValue = ALLTRIM(This.Value)
WAIT WINDOW cNewValue NOWAIT NOCLEAR
NODEFAULT
************************

If the type is numeric, suitably handle the variable with the same idea.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Hi ramani,

I have tried your suggestion, This.Value still contains the original value not the new value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top