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!

Problem with Keypress & Valid events

Status
Not open for further replies.

terosoft

Programmer
Jun 4, 2003
73
AR
Hi!

I have a little issue that bothers me (my customers, actually) from time to time and I never found a good solution.

I´ve made subclasses of textboxes to act as an interface to particular tables in a database, for example the customers table so whe you enter the customer code or his/her name the textbox fires all needed methods to show all required data on a particular window. This worked perfectly until I added the feature to do "advanced searches" on that particular object by pressing a function key, let´s say search by preferred product brand if you press [F5]. The search is made and all occurrences -if there are more than 1- are shown on a list for the user to choose from. Then the proper Customer ID is put on the textbox and Valid event is fired. All this works perfectly, the search completes and the window is filled up with the required data. Then the problem appears, but randomly. After the special search returns control to KeyPress event an ASCII char corresponding to the function key is added at the beginning the textbox value so when the user leaves the textbox gets an error. I tried to force extra char deletion by issuing {HOME}+{DEL} but not always work.
Sample code:


** Code begins
Code:
txtCliente.Keypress:

LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL tF5 as Integer, tF6 as Integer, tComilla as Integer, tApostrofe as Integer
tF5 = -4
tComilla = 34
tApostrofe = 39

DO CASE
CASE INLIST(nkeycode, tComilla, tApostrofe)
	KEYBOARD '{BACKSPACE}'
	KEYBOARD '´'
CASE nKeyCode = tF5 AND this.tienebusqueda
	THIS.busquedaavanzada
*	KEYBOARD '{HOME}'  && Tried with these here but doesn´t work, as sometimes
*	KEYBOARD '{DEL}'   && it erases the first customer ID digit.
ENDCASE
RETURN



txtCliente.BusquedaAvanzada:

LOCAL sValor as String, sQue_Busco as String, oTabla as Object

sValor = ""

DO FORM clientes_busqueda_avanzada TO sQue_Busco

IF LEN(ALLTRIM(sQue_Busco)) > 0
	f_esp.dbf.motor.tabla_busquedaavanzada('vista_clientes', 'Nombre', sQue_Busco, "xTabla")
	IF USED("xTabla")
		IF RECCOUNT("xTabla") > 1
			oTabla = CREATEOBJECT("tabla_clientes", "xTabla")
			oTabla.Show
			IF oTabla.Retval
				sValor = xTabla.idCliente
			ENDIF
			oTabla.Release
		ELSE
			sValor = xTabla.idCliente
		ENDIF
		USE IN xTabla
		IF VAL(sValor) <> VAL(this.Value)
			THIS.Value = sValor
			this.changed = .t.
			this.Valid && Here customer ID is searched and data retrieved to be shown.
		ENDIF
	ENDIF
ELSE
	this.changed = .F.
ENDIF
RETURN
** Code ends.

I know that I´m doing double search on the database here (adv search and Valid event) but I needed to add this feature over a working application, so the code had to be maintained compatible.

BTW, I´m using VFP8 w/sp1. Any help will be really appreciated.

Gerardo Czajkowski
ltc.jpg
 
Just a thought, in the Gotfocus event could you not check for the value of the first character and if the character is the function key character use substr() to remove it from the string

eg:

if substr(this.whatever.value,1,1) = 'the f5 character'
this.whatever.value = substr(this.whatever.value,2)
endif


 
Try replacing the lines:

* KEYBOARD '{HOME}' && Tried with these here but doesn´t work, as sometimes
* KEYBOARD '{DEL}' && it erases the first customer ID digit.



....with:

NODEFAULT


Slighthaze = NULL
craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
Hi
txtCliente.Keypress:

LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL tF5 as Integer, tF6 as Integer, ;
tComilla as Integer, tApostrofe as Integer
tF5 = -4
tComilla = 34
tApostrofe = 39

DO CASE
CASE INLIST(nkeycode, tComilla, tApostrofe)
KEYBOARD '{BACKSPACE}'
KEYBOARD '´'
NODEFAULT && this is not a must
CASE nKeyCode = tF5 AND this.tienebusqueda
THIS.busquedaavanzada
NODEFAULT
ENDCASE

:)

____________________________________________
ramani - (Subramanian.G) :)
 
ramani has shown you what I suggested above, except I would make one change if you want to use the NODEFAULT in the first case also...

CASE INLIST(nkeycode, tComilla, tApostrofe)
*!* KEYBOARD '{BACKSPACE}' && Comment this line out
KEYBOARD '´'
NODEFAULT

Slighthaze = NULL
craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
Thanks, I'll try and let you know as I can´t test it on my machine because the problem seems to happen only on slower w98 machines. I never could mimic that problem on w2k which I use.





Gerardo Czajkowski
ltc.jpg
 
I´ve tried your suggestion and worked perfectly, thank you again.

Gerardo Czajkowski
ltc.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top