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

Pageframe Controls reference

Status
Not open for further replies.

kstieb

Programmer
Mar 29, 2005
11
CA
I am having some problems getting this code to work. Hope someone can help me. What I am trying to do is have the form keypress event enter a value of 10 in any text box on Page three of a pageframe (named PgfRelated) if I hit the 0 key, then move to the next text box. The other number keys (1 thru 9) enter their values normally, and then move to the next text box.
Here is my code I am trying...

LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL lcWord

IF (THISFORM.PgfRelated.ActivePage = 3) THEN

m.loActiveControl = THISFORM.PgfRelated.Page3.ActiveControl
lcWord = m.loActiveControl.Value

DO CASE
CASE nKeyCode = 48
lcWord = 10
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 57
lcWord = 9
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 56
lcWord = 8
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 55
lcWord = 7
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 54
lcWord = 6
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 53
lcWord = 5
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 52
lcWord = 4
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 51
lcWord = 3
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 50
lcWord = 2
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 49
lcWord = 1
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
ENDCASE

ENDIF

I have used code similar to this on a form without a pageframe, and it works well. My problem seems to be the pageframe. My reference does not work properly or something.
 
Hi
Set the forms

KEYPREVIEW = .t.

That should solve your problem.. While I dont comment too much as to everything in it.. lot of codeing has been done. You can simplify..

LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL lcWord

IF (THISFORM.PgfRelated.ActivePage = 3)

m.loActiveControl = THISFORM.PgfRelated.Page3.ActiveControl
lcWord = m.loActiveControl.Value

DO CASE
CASE BETWEEN(nKeyCode,49,57)
lcWord = CHR(nKeyCode)
CASE nKeyCode = 48
lcWord = 10
ENDCASE

m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT

ENDIF

This would have been sufficient. :)

____________________________________________
ramani - (Subramanian.G) :)
 
Thanks for the help. My mind was going blank and I forgot to set the KeyPreview to .T.
I had to modify your code sightly to get it to work properly. Something I had found in the earlier example I posted from my previous forms. Here is the final code.

LPARAMETERS nKeyCode, nShiftAltCtrl
LOCAL lcWord

IF (THISFORM.PgfRelated.ActivePage = 3)

m.loActiveControl = THISFORM.PgfRelated.Page3.ActiveControl
lcWord = m.loActiveControl.Value

DO CASE
CASE BETWEEN(nKeyCode,49,57)
lcWord = CHR(nKeyCode)
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
CASE nKeyCode = 48
lcWord = 10
m.loActiveControl.Value = lcWord
KEYBOARD '{TAB}'
NODEFAULT
ENDCASE

ENDIF

The reason I had to do it this way is because for some reason the other way (similar to what you posted) the program froze...it was looping on the keypress. However, now it works great.
Appreciate the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top