ANSI Standard PL/B Language and Visual PL/B
Events are everything in the windows environment. You click a key and it causes an event. You move the mouse and it causes an event.
When you create a form with Sunbelt's Visual PL/B form designer you can double click an object and add coding for any of the events that object type can detect.
Sometimes you need to evaluate a key press to anticipate what the user is trying to do. Consider the example shown beloe. We have a datalist of items and an edit text with a value. When the user updates the value the program updates the currently selected item in the datalist.
What we want to do is be responsive to the user. If they press an arrow up or arrow down key we want to detect that and automatically move to the previous or next line in the data list. So How do we get that keystroke?
The answer is to check the KEYPRESS event in the PLF (form) file using the designer. (See second screen print below).
The only problem with this is that the various event responses are avaiilable in the designer as "#" variables. That means that they can be seen in the designer only. We could process the event right there in the code in the designer, but at MMCC we don't do that. Rather we move a literal to the variable "ACTION" and evaluate it back in the mainline after the WAITEVENT.
To capture the event data, we move the # variable to a variable in our standard set of variables found in our COMMONWK include unit. This allows us to transfer them from the PLF code to the mainline code.
We'll add more to this article later. For now, just check out the code.
The EventResult will give you the numerical value of the key that's been pressed.
Code in the PLform on the Key Press event:
MOVE "KEYPRESS-QOH", ACTION
MOVE #EventChar, EventChar
MOVE #EventMod, EventMod
MOVE #EventResult, EventResult
MOVE #EventType, EventType
Code in the mainline to see what we got:
IF (ACTION = "WINDOWCLOSE" |:
ACTION = "EXIT")
ELSEIF (ACTION = "KEYPRESS-QOH")
DISPLAY "Event Result:":