What is DoEvents, how do you use it?
Main Topics
Browse All TopicsHello Experts,
I have written a VB6 that downloads an Access db, synchronizes it with another local db, then uploads the online db back, all this is done w/o human interaction. I cannot do this directly as my ISP blocks outside connections.
For the download/upload, Im writing a ftp script as a .txt file, then calling the ftp script from a .bat file. As other VB code does not wait for my shell code to finish, after I run my batch file, I activate a VB Timer to wait 30seconds before executing the next VB command. As the db grew, I increased the timer to 45s, and now its at its maximum of 65s.
I know I can use a secondary timer, and flip/flop between the two to increase minutes, or use a For loop, but I think a timer is not safe at all as the download/upload speed depends on external factors as well (network traffic, loose connection, etc.)
Another person advised using a file marker, wher a dummy file is created, then having the batch file delete the dummy file, while I have an empty Do While File exists Loop, but as the ftp takes minutes, VB6 suspects that this is an endless loop and crashes the system.
Any suggestions?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I recommend you ditch the FTP approach via a .txt file completely. You can't tell whether the download was successful or if the connection was dropped, etc...
Buy a third-party control to do the FTP legwork for you (approx <$200), or use something more reliable such as:
http://www.vb-helper.com/h
To oversimplify... DoEvents is just a simple statement that instructs your program to process any pending Windows messages, so if used inside of a tight/lengthy loop it gives your program a chance to re-draw itself (e.g. update a progress bar), and tell Windows "Hey, I'm still alive and running" so your program isn't flagged as not responding.
Will cause Not Repsonding:
Do FileExists
'Do nothing
Loop
Will not cause a Not Responding:
Do FileExists
DoEvents
Loop
Though I agree with Idle Mind's suggestion of ditching the text file method. Last time I used VB for an FTP operation I referred to the WinINet API documentation, and wrote my own functions that wrapped around Windows' If you're up for the task I'd be happy to share my code, though it would need a bit of tweaking for your specific purpose. Maybe better to hunt around for a free or cheap control...
Business Accounts
Answer for Membership
by: tgerbertPosted on 2009-10-28 at 12:46:49ID: 25687439
Put a DoEvents inside your empty Do While marker file exists loop.