WAIT-FOR statement (ABL only)

This WAIT-FOR statement instructs the AVM to stop executing the current block until a specific ABL event occurs. The AVM continues to respond to all other incoming events and execute any associated triggers or event procedures while in this wait state.

Note: ABL supports a separate version of the WAIT-FOR statement (.NET WAIT-FOR) that blocks for .NET, as well as ABL, events. For more information, see the WAIT-FOR statement (.NET and ABL) reference entry.

Syntax

WAIT-FOR event-list OF widget-list 
  [ OR event-list OF widget-list ] ...
  [ FOCUS widget ]
  [ PAUSE n ]
WAIT-FOR "WEB-NOTIFY" OF DEFAULT-WINDOW
  [ PAUSE n ]
  [ EXCLUSIVE-WEB-USER ]
event-list

A space or comma-separated list of user-interface events and other ABL events to wait for.

An event can be any event described in the Handle-based Object Events Reference.

widget-list

A space- or comma-separated list of widgets with which the event is associated. For more information on referencing widgets, see the Widget phrase reference entry.

FOCUS widget

Specifies the widget that initially receives input focus when the WAIT-FOR statement is executed. The value widget must be a valid reference to a widget (a widget name or handle) that is currently displayed and enabled.

PAUSE n

Specifies a time-out interval for the WAIT-FOR statement. The value n can be any numeric expression, including a fractional value. You can choose a whole or a fractional value for the time-out interval. If the time-out period you specify is a fractional value, the value is rounded to the nearest whole millisecond. If a period of n seconds elapses between events, the WAIT-FOR automatically terminates.

Examples

This procedure defines two buttons, defines triggers for them, and enables them. The procedure then waits for the user to close the current window. The initial focus is placed on the button labeled MORE. The user can then choose buttons continuously until closing the window or exiting with the END-ERROR key.

r-wait.p

DEFINE BUTTON more-button LABEL "MORE".
DEFINE BUTTON next-button LABEL "NEXT".

FORM Customer.CustNum Customer.Name more-button next-button
  WITH FRAME brief.

FORM Customer EXCEPT Customer.CustNum Customer.Name
  WITH FRAME full.

ON CHOOSE OF more-button
  DISPLAY Customer EXCEPT Customer.CustNum Customer.Name WITH FRAME full.

ON CHOOSE OF next-button DO:
  HIDE FRAME full.
  FIND NEXT Customer NO-LOCK NO-ERROR.
  IF AVAILABLE Customer THEN
    DISPLAY Customer.CustNum Customer.Name WITH FRAME brief.
END.

FIND FIRST Customer NO-LOCK.
DISPLAY Customer.CustNum Customer.Name WITH FRAME brief.

ENABLE more-button next-button WITH FRAME brief.

WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW FOCUS more-button.

If the user closes the current window then execution continues after the WAIT-FOR statement. In this case, the procedure ends because there are no more statements.

The following procedure uses the PAUSE option of the WAIT-FOR statement so that you automatically jump ahead to the next record if the user does not perform any action within three seconds after the customer information is displayed:

r-waitpn.p

DEFINE VARIABLE jump-ahead AS LOGICAL NO-UNDO INITIAL TRUE.

DEFINE BUTTON more-button LABEL "MORE".
DEFINE BUTTON next-button LABEL "NEXT".

FORM Customer.CustNum Customer.Name more-button next-button
  WITH FRAME brief.
FORM Customer EXCEPT Customer.CustNum Customer.Name
  WITH FRAME full.

ON CHOOSE OF more-button DO:
  DISPLAY Customer EXCEPT Customer.CustNum Customer.Name WITH FRAME full.
  jump-ahead = FALSE.
END.

ON CHOOSE OF next-button DO:
  jump-ahead = TRUE.
END.

ON WINDOW-CLOSE OF CURRENT-WINDOW DO:
  QUIT.
END.

ENABLE more-button next-button WITH FRAME brief.

DO WHILE TRUE:
  IF jump-ahead THEN 
    RUN next-cust.

  WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW OR CHOOSE OF next-button
    FOCUS more-button PAUSE 3.
END.

PROCEDURE next-cust:
  HIDE FRAME full.
  FIND NEXT Customer NO-ERROR.
  IF AVAILABLE Customer THEN
    DISPLAY Customer.CustNum Customer.Name WITH FRAME brief.
END.

In this example, the code for finding the next Customer has been moved to an internal procedure. The WAIT-FOR statement has been placed inside a DO loop. The loop iterates when the user chooses the NEXT button or three seconds elapse. (If the user closes the window, the QUIT statement is executed and the loop does not iterate.) On each iteration, if the variable jump-ahead is TRUE, then the next-cust procedure is run to find and display the next Customer. If the user chooses the MORE button for a Customer, jump-ahead is set to FALSE. This prevents the procedure from automatically jumping ahead to the next Customer. Instead, the user can spend time examining the data. To move ahead to the next Customer, the user must explicitly choose the NEXT button. At that point, jump-ahead is reset to TRUE.

Notes

See also

DISABLE statement, ENABLE statement, ON statement, Trigger phrase, WAIT-FOR statement (.NET and ABL), Widget phrase