Whatever you define with ON KEY LABEL will run as if EXECSCRIPT is done, outside of any scope. You don't have the THISFORM context. Therefore donÄt try to do this with ON KEY LABEL.
As the example states for a caption "\<Open" ALT+O becomes an access key. That doesn't only work with controls having a caption like the command button or a checkbox or option of an option group, this works for a separate label control, too, in conjunction with the tab stop mechanism: As a standalone Label doesn't get focus but can be assigned a tab index, the focus will go to the control with next tab index after that.
So if you assign tab order correctly '(Menu: View->Tab Order -> Assign interactively or by list helps to not need to set all tabindex properties manually), you can use a Label next to a Textbox to give focus to the textbox. Let's say the label has tabindex 15 and the textbox has tabindex 16, then that label becomes the landing point to get focus to the textbox.
As you want ALT+Z, that's in conjunction. All you need is a label that has a Z as access key, like "Peanutbutter \<Zandwich" and the magic happens.
You've got to remember that a user can hit your chosen key combination (ALT+Z in this case) at any time, in any part of the application. But your textbox is only active when the relevant form is open and active. If you try to give focus to the textbox by means of ON KEY LABEL at any other time, it will cause an error.
For that reason, ON KEY LABEL is a bad choice in this case. In fact, it's a bad choice in almost all cases, and should generally be avoided.
If your aim is give the user a shortcut key to access a given textbox, you can do that more easily with the usual [tt]\<[/tt] mechanism (as mentioned by Olaf, above). If you are not sure how that works, simply place [tt]\<[/tt] before the relevant letter in the textbox's caption. (By which I mean the caption of the label that immediately precedes the textbox in tab order.)
For example, if the textbox contains the address of a zoo, you would write the caption of the label as [tt]Address of \<zoo[/tt]. The letter Z will appear underlined. If the user than hits ALT+Z, that will immediately give focus to the textbox.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Already in Hacker's Guide to VFP6, Tamar, Ted and Steven wrote about the use of keypress and keypreview for reacting to user input individually without having those problems that come with ON KEY LABEL.
I implemented the keypress and keypreview feature by adding a property for usable Shortcuts in each class that might have the need for a shortcut. The prop is called ._FKeysAllowed and can hold a comma-seperated list of shortcuts like "F1,F3,CTRL+Y,CTRL+P" a.s.o. and in keypreview(form)/keypress(object) I check the current objects prop-value and ignore or react to it.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.