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

Changing Date Value with On Key Label Assignments

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
US
I have been attempting to change the value of a date field on a form by using On Key Label Assignments.<br><br>In the Got Focus event I have the following:<br><br>ON KEY LABEL LEFTARROW myDate.value = myDate.value - 1<br>ON KEY LABEL RIGHTARROW myDate.value = myDate.value + 1<br>ON KEY LABEL UPARROW myDate.value = myDate.value + 7<br>ON KEY LABEL DNARROW myDate.value = myDate.value - 7<br>ON KEY LABEL PGUP myDate.value = GOMONTH(myDate.value, 1)<br>ON KEY LABEL PGDN myDate.value = GOMONTH(myDate.value, -1)<br>ON KEY LABEL HOME myDate.value = DATE()<br><br><br>In the Lost Focus event I clear the assignments with.<br>ON KEY LABEL LEFTARROW<br>ON KEY LABEL RIGHTARROW<br>ON KEY LABEL UPARROW<br>ON KEY LABEL DNARROW<br>ON KEY LABEL PGUP<br>ON KEY LABEL PGDN<br>ON KEY LABEL HOME<br><br>I run the form and attempt to modify the date and generate an error &quot;Object myDate not found&quot;<br><br>I have tried every method of referencing (This, ThisFormset etc.) that I know of but VP6.0 doesn't like any of them.<br><br>I suspect there is there a better way to accomplish my task -- the optimum would be to have a calendar drop down.<br><br>Any suggestions will be appreciated.
 
The problem is this: the ON KEY LABEL assignments trap keystrokes within the entire application (not just the form).<br><br>One possible solution you could try is to directly reference the textbox (i assume mydate is a textbox).<br>ON KEY LABEL LEFTARROW [frmMyForm].myDate.Value = [frmMyForm].myDate.Value + 1<br><br>Of course, you would substitute the name of your form for [frmMyForm].<br><br>A second solution, and much cleaner than the first, would be to use the KeyPress event.<br><br>HTH,<br>Jon
 
Thanks for the reply, I'll try the keypress event, I hadn't thought of that.&nbsp;&nbsp;It should be simple to test for the appropriate keys.<br><br>&nbsp;&nbsp;You don't perhaps know of an API solution for a calendar that could be part of an object like a dropdown box?&nbsp;&nbsp;That would allow the user the cleanest way to choose a date.<br><br>--cd.
 
CDavis<br><br>Check UniversalThread.com in the files section under ActiveX controls and Classes. They have some calendar controls, maybe one will do what you want.<br><br>Jon
 
I've been able to get the date values to change, however the date object loses focus when the keystroke is processed, is there a way to maintain the focus -- I could set a flag in the keypress event and reset the focus from the object that is receiving the focus based upon that flag, but that doesn't seem very clean.<br><br>Any suggestions?<br><br>Thanks -- cd.
 
To answer your original question, CDavis, you are using an invalid reference.&nbsp;&nbsp;A line of your code was:<br><br><FONT FACE=monospace>ON KEY LABEL LEFTARROW myDate.value = myDate.value - 1</font><br><br>It should have been:<br><br><FONT FACE=monospace>ON KEY LABEL LEFTARROW <font color=red>This</font>.value = <font color=red>This</font>.value - 1<br></font><br><br>assuming this code was in the GotFocus of the control you were trying to change.&nbsp;&nbsp;One downside to ON KEY LABEL approaches is that you sometimes cannot be sure of the situation when the key is pressed.&nbsp;&nbsp;For example, if FormA's Init method had an <FONT FACE=monospace>ON KEY LABEL F2 DO LOOKUP WITH THISFORM.TXTNAME.VALUE</font>, and while using FormA a user pressed a command button that popped up another form on top, then the user pressed F2, &quot;THISFORM&quot; may refer to the second form, not the first.<br><br>All around, the KeyPress suggestions are better, because they encapsulate the behavior better. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
I've continued to work on this as an interesting exercise and I appreciate all the help. The application consists of only one form however, I recognized the danger of the On Key assignments thus the resetting of the On Key Labels in the LostFocus event.&nbsp;&nbsp;I still haven't been satisfied with my results using the KeyPress event because the arrow keys are processed and move the focus away from the object.<br><br>So, today I created a set of spinners to do the same task and it presents a more functional process.<br>--cd.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top