How do I monitor a Command button click while in a DO-LOOP?
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
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.
Thanks - I forgot about the DoEvents function. It works!