[Stackoverflow] [Progress OpenEdge ABL] How to use LASTKEY in OpenEdge

Status
Not open for further replies.
A

Allan Green

Guest
This isn't so much a new question for you to answer (though comments of course are very welcome!) but a pointer to anyone who has struggled for any length of time with the LASTKEY function in OpenEdge. Hopefully there is enough in this post for Google to guide anyone here who needs to be!

I've just wasted pretty well a whole day trying to understand why this (simplified version) didn't work;

Code:
DO WHILE NOT lUserQuit:
   DO ON ENDKEY UNDO, LEAVE:
      iIssueNumber = ?.
      UPDATE iIssueNumber
             GO-ON(RETURN F4 F6)
             WITH FRAME iIssueNumber-f
                  ROW 10
                  COLUMN 5
                  NO-LABELS.
      END.

   RUN WrtToLogfile("{&FILE-NAME}: {&LINE-NUMBER}: " +
                    "Issue number from keyboard: " +
                       STRING(iIssueNumber)) +
                    " KEYFUNCTION(LASTKEY):" +
                        cFunctionLastKey).

   IF KEYFUNCTION(LASTKEY) = "END-ERROR" THEN DO:
      lUserQuit = TRUE.
      iIssueNumber = ?.
      END.
   ELSE IF KEYFUNCTION(LASTKEY) = "F6" THEN DO:
      ....
      END.
   END.

(WrtToLogfile is a function which adds the value of its character expression argument to a logfile... not included for brevity!)

The more experienced of you will notice that I've used LASTKEY a number of times to access the last keypress by the user in the UPDATE. And this is the error. LASTKEY can only be used once. The call to WrtToLogfile gobbles up the value left by the UPDATE and from then on the code just never gets to see it (The solution is to copy its value to an integer variable immediately after it is set and then use that...)

Its sort of obvious but only when you know it!

PS I'm quite sure that this could all be done much better with an event driven program but the code I'm supporting is very old :) (and so am I).

(I have the "ABL Reference" PDF page for the LASTKEY function open on my desktop and it doesn't warn you of this!)

Best wishes to everyone...

Allan

Continue reading...
 
Status
Not open for further replies.
Top