PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Andy Flowers on December 20, 2005, 06:51:16 PM

Title: Monitoring Command Button in a DO - LOOP procedure
Post by: Andy Flowers on December 20, 2005, 06:51:16 PM
How do I monitor a Command button click while in a DO-LOOP?
Title: Monitoring Command Button in a DO - LOOP procedure
Post by: TechSupport on December 20, 2005, 07:02:58 PM
Here is a very simple example:


Global gExitLoop As Long

'----------------------------------------------------------------------------------------
Function FORM1_CMDENDLOOP_BN_CLICKED ( _
                                  ControlIndex     As Long,  _  ' index in Control Array
                                  hWndForm         As Dword, _  ' handle of Form
                                  hWndControl      As Dword, _  ' handle of Control
                                  idButtonControl  As Long   _  ' identifier of button
                                  ) As Long

   gExitLoop = %TRUE
   
End Function


'--------------------------------------------------------------------------------------------
Function FORM1_CMDSTARTLOOP_BN_CLICKED ( _
                                      ControlIndex     As Long,  _  ' index in Control Array
                                      hWndForm         As Dword, _  ' handle of Form
                                      hWndControl      As Dword, _  ' handle of Control
                                      idButtonControl  As Long   _  ' identifier of button
                                      ) As Long

   Do
      FF_DoEvents
      If gExitLoop Then Exit Do
   Loop                        
   
   MsgBox "loop has been exited"
   
End Function
Title: Monitoring Command Button in a DO - LOOP procedure
Post by: Roger Garstang on December 20, 2005, 11:03:19 PM
One of my favorite things is on clicking the button, disable it...then check for the enabled status of the button in the loop.  I saw a lot of web sites doing this and liked it since it eliminates the possibility of it clicking twice and doing something in the loop twice or the global being set again after the loop exits causing unwanted results on entry to the loop again, etc.  And it is a visual notification to the user that they clicked the button and it is stopping/starting/whatever.

Only issues with disabling is if it is the default button sometimes it is drawn funny, and sometimes if it is the cancel button Windows will beep on exiting the app if it is disabled.
Title: Monitoring Command Button in a DO - LOOP procedure
Post by: Andy Flowers on December 23, 2005, 12:14:43 PM
Thanks - I forgot about the DoEvents function. It works!