John W Colby
jwcolby at gmail.com
Thu May 30 13:42:42 CDT 2013
I grabbed some code off the internet to check if a file is locked. The code was (too) simple, and just tried to open the file read/write. If it succeeded the file is not locked. Sounds good right? Well... if the file does not exist then it CREATES the file! Ooops. I had to add a "wrapper" to do a DIR() to see if the file exists, and if not return a false (not locked since it doesn't exist) else try to open it. The code I was building was some stuff to use FSO to zip a file and that is just flaky, but doesn't require external dlls. The code creates the zip file (directory really) if it doesn't exist and then stuffs the file in it. Except that my lock check was creating the file before this code ever got a chance to do so. I scratched my head over that one for a good while. And of course all of this was buried way down in other code that had to run first... BTW, some of you may remember my timer class. This zip code was using a call out to Windows to Sleep(). Unfortunately Sleep causes the user interface to go unresponsive during the Sleep. So I added a function to my timer class mSleep(lngMSToSleep as long) and then used the timer stuff to watch the timer for that many milliseconds in a while loop, but calling DoEvents inside of that loop. It looks like a sleep but the DoEvents allows Windows to process the event queue for the app so I can still move around in the app and do things while the code is "sleeping". -- John W. Colby Reality is what refuses to go away when you do not believe in it