Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Exiting a loop gracefully
Message
From
28/04/1999 08:07:34
 
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00212793
Message ID:
00212904
Views:
19
>I have a backup program that uses a DO WHILE loop to copy files from one drive / directory to another...
>
>The loop is structured as follows:
>
>
<b>
>nIndex = 1
>DO WHILE nIndex <= ALEN( aFileList, 1 ) <i>AND ! THISFORM.lAborted</i>
>   .
>   .
>   .
>ENDDO
></b>
>
>The user clicks "Start" to begin the backup.
>
>The caption on the "Start" button changes to "Cancel"
>
>When the "Cancel" button is clicked, I set THISFORM.lAborted TO .T. but the loop doesn't exit...
>
>What am I missing here??
>

In all probability, the event isn't being registered and acted on until the loop completes; adding a DOEVENTS() to the loop, so that UI events get processed by VFP while the loop is running would probably allow the event to be recognized and acted on by VFP at the end of the current file copy action.

I'd probably restructure to look something like:
FOR nIndex = 1 TO ALEN( aFileList, 1 )
   * Do copy stuff
   DOEVENTS()
   IF thisform.lAborted
      EXIT
   ENDIF
ENDFOR
Paul's recommendation about using SHFileOperation is a good one; the necessary SHFILEOPSTRUCT structure can be created using Paul's POINTERS class or my CLSHEAP class. SHFileOperation will do some useful stuff for you, like throw up a progress bar, trap file copy errors without triggering a VFP error (you can detect if any occurred by checking the fAnyOperationsAborted member of the SHFILEOPSTRUCT on return. Read the MSDN entry on the SHFILEOPSTRUCT carefully, since you can construct lists of files and pass them to the API call, and each entry can contain wildcards as appropriate. There are also a number of flags you'll want to look at. This is all covered in the MSDN doc.


>TIA
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform