Member Avatar for icsantos

I created a form containing a timer control named tmrChkDir and a command button named cmdPause. What I need help on is how to check if the user clicked on the cmdPause button while the Timer event of tmrChkDir is in progress, and pause execution until another mouse click occurs.

For example, within the Timer event of tmrChkDir, I have this code:

THIS.ENABLED = .F.     && suspend timer

lnTotFiles = ADIR(laFiles, "*.ERA")
FOR lnCntFiles = 1 TO lnTotFiles
     DO myprocess WITH laFiles[lnCntFiles,1]
     IF THISFORM.cmdPause.CLICK()
          MESSAGEBOX("Click OK to resume processing")
     ENDIF
NEXT lnCntFiles

THIS.ENABLED = .T.   && reactivate timer

cmdPause.click() contains this code:

IF THISFORM.cmdPause.CAPTION = "Pause"
    THISFORM.cmdPause.CAPTION = "Resume"
    THISFORM.tmrChkDir.ENABLED = .F.
ELSE
    THISFORM.cmdPause.CAPTION = "Pause"
    THISFORM.tmrChkDir.ENABLED = .T.
ENDIF

The problem is, THISFORM.cmdPause.CLICK() in the Timer event always returns .T. whether or not I click on the Pause command button.

So how should I test if the Pause button was clicked within the FOR-NEXT loop in the Timer event?

Any help would be greatly appreciated. Thanks!

Member Avatar for icsantos

Never mind, I figured it out. I replaced

IF THISFORM.cmdPause.CLICK()
          MESSAGEBOX("Click OK to resume processing")
     ENDIF

with

DOEVENTS
     DO WHILE .T.
          IF THISFORM.cmdPause.ENABLED
               EXIT
          ENDIF
          DOEVENTS
     ENDDO

And instead of a single command button that toggled between "Pause" and "Resume", I created a Pause command button and a Resume command button.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.