PDA

View Full Version : Slow down, you’re going too fast.


JimS
08-28-2004, 12:31 AM
How do I make sure that one piece (line) of code finishes, before the next line of code is executed? I’ve used Application.Sleep(x) but the length of time it needs to sleep, will be dependant on the user’s particular system, so what works on my computer, might not on someone else’s.

Here is what I’m doing:
1) I delete a picture file

2) I rename a different picture file, same name as the one I deleted

3) I copy the new picture to the old picture’s folder

--I don’t want to use Application.Sleep(x) here --

4) I refresh a web object that displays the picture.

My problem is that I get a Web Object refresh, before the new picture is in place.

itamar
08-28-2004, 03:06 AM
I'm happy that i'm not the only one that still awake.

are you using Functions, lets say function that delete the file and only then calls the next step in your code?

cause what you were saying about using the sleep(x) sounds pretty bad idea, and you figured it out your self.

Itamar.

Worm
08-28-2004, 03:24 AM
Here's some code that uses a while loop to wait for File.Delete to happen. Times out after 10 seconds


File.Delete("Autoplay\\images\\image1.jpg", false, true, false, nil)
nTime = 0
nBaseTime=String.ToNumber(DLL.CallFunction(_System Folder .. "\\winmm.dll", "timeGetTime", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL))
while (File.DoesExist("Autoplay\\images\\image1.jpg")) and (nTime < 10000) do
--wait for the file to be deleted or 10 seconds to have elapsed
--otherwise we could be in an infinite loop
nTime=String.ToNumber(DLL.CallFunction(_SystemFold er .. "\\winmm.dll", "timeGetTime", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL)) - nBaseTime
end
if nTime > 10000 then
Dialog.Message("Error", "Unable to delete the file Image1.JPG")
end

JimS
08-28-2004, 02:33 PM
itamar, thanks for the suggestion. Yes, I am using Functions. With AMS5, it seems that I do 90% of my programming as Global Functions, so much so, that I’m considering changing my user name to Mel Function
:)

Worm, thank you for the code. I’ll give it a try this evening. I’m sure that will do the trick. I was sort of hoping that I had overlooked some type of built in ‘wait until finished’ function.

I had considered using a similar type of loop using the page’s On Timer event. I didn’t really want to go that route if I didn’t have to, because I’ll be using the On Timer for other things too. It would mean I’d have to add more conditionals to the On Timer code.

That’s what makes your code so sweet. That Systems’ DLL call for the timer, makes it much simpler to implement. In effect, you have given us a separate clock to use concurrently with the On Timer event. That’s cool!

Thanks again.

Corey
08-28-2004, 02:39 PM
Mel is a superb choice of name, second only to Lou. I'm behind you 100%.

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)