DIALOG Status is Not Reset in Interpreter When Program Ends (44495)






This article was previously published under Q44495

SUMMARY

In Macintosh QuickBASIC Version 1.00, the DIALOG(1) status is not reset when a program ends. For example, the DIALOG(1) function returns the number of the last button that was pushed from the previous run of the program if a new button has not yet been pushed.

This problem occurs only when you make consecutive runs of a program within the QuickBASIC editor. This is not a problem with compiled programs.

To work around this behavior, you should first check the value of DIALOG(0), which is a "1" if a button was clicked after the program was started. You can then invoke DIALOG(1) to see which button number was clicked.

MORE INFORMATION

The DIALOG(0) function is the central function around which you should design a program to trap a button (or other) event. DIALOG(0) returns the next event in the queue of events that occurred since the last invocation of DIALOG(0), or since the program began.

Note: DIALOG(0) should be invoked only once per cycle in the loop that is polling the value of DIALOG(0). For example, you should let x=DIALOG(0) in the beginning of the loop, and then use "x" in all subsequent IF statements in that loop cycle. This analyzes one event per loop cycle.

Code Example

The following program demonstrates the behavior of DIALOG(1), which works correctly the first time it is run within the editor, but which doesn't work correctly the second time:
   ' initialize the button:
   BUTTON 1,1,"Press to END",(100,100)-(200,200),1
   ' THIS WHILE LOOP IS DESIGNED TO WAIT UNTIL THE BUTTON IS
   ' PUSHED AND THEN EXIT. IT WILL NOT ENTER THE LOOP IN THE SECOND
   ' RUN OF THE PROGRAM BECAUSE DIALOG(1) WILL NOT BE RESET TO 0.
   WHILE DIALOG(1) = 0
     initdialog = DIALOG(0)
   WEND
   PRINT "END OF PROGRAM"
   END
				
As a workaround, use the DIALOG(0) function instead of DIALOG(1) to test for button pushes. For example:
   BUTTON 1,1,"Press to END",(100,100)-(200,200),1
   BUTTON 2,1,"Press to do nothing",(1,30)-(160,60),1
   WHILE NOT ( DIALOG(0) = 1 AND DIALOG(1)= 1 )
   WEND
   PRINT "BUTTON ";DIALOG(1);" WAS PUSHED"
   PRINT "END OF PROGRAM"
   END
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB44495