Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ


How can I enable cancellation in a loop by ChrisRChamberlain
Posted: 24 Apr 04 (Edited 2 Dec 08)

If you need a simple way to enable a user to cancel out of loops, in particular where external processing is involved, try the following, (VFP 7 and above).

If an external process is running, it is generally easier to allow the external process to complete, resolve any issues arising and then exit the loop.

Add a command button to a form and name it .cmdCancel, with .Enabled = .F.
Add two properties to the form, .lQueryExit and .lCancelButton.

In the .MouseEnter() event of .cmdCancel put :-

THISFORM.lCancelButton = .T.

In the .MouseLeave() event of .cmdCancel put :-

THISFORM.lCancelButton = .F.

In the following code, the command button is enabled for a couple of seconds during which time, should a user click on .cmdCancel, the form property .lQueryExit becomes true enabling the relevant MESSAGEBOX dialog to take place.

The form property .lCancelButton only becomes true if the mouse click was detected whilst the mouse was over the command button .cmdCancel.

There is no requirement for code in the command button as the .Click() event was not fired but as far as the user is concerned it appears to have happened.

For simplicity, all the required code remains within the loop and in the example below, the user can skip a record, ignore and continue, or cancel the entire operation.

LOCAL inval1, lnSeconds, lnAnswer



        && Allow user to cancel

        WITH .cmdCancel
            .Enabled    = .T.

        lnSeconds = SECONDS()
        DO WHILE .T.
            inval1 = INKEY(0.06,'HM')
            IF SECONDS() > lnSeconds + 2.5
            IF inval1 = 151    AND .lCancelButton
                .lQueryExit    = .T.

        WITH .cmdCancel
            .Enabled    = .F.

        IF .lQueryExit
            lnAnswer =    MESSAGEBOX(                            ;
                [Do you want to skip the deletion of ]        ;
                + ALLT(TABLENAME.filename)                    ;
                + [?]                                        ;
                + CHR(13)                                    ;
                + CHR(13)                                    ;
                + [If you answer 'Cancel', you will cancel the entire operation] ,;
                3 + 32 + 256                                ,;
                [Skip file deletion or cancel operation])
            DO CASE
            CASE lnAnswer    = 2
            CASE lnAnswer    = 6
                .lQueryExit = .F.
                .lQueryExit = .F.

        && Processing, internal and/or external, here


    IF .lQueryExit

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close