Is there a way to add a timeout value to a line of code or functio

C

Chris_In_Raleigh

Is there a way to do a 'timeout' on a line of code or a function. I have a
VBA program that downloads files from our FTP server and software updates
from websites and saves them to specific folders on our computers. This is
used to keep everyone up to date on project files etc. The problem is that
sometimes the program hangs on waiting for a response from the server. I
have to close Excel from the task manager and start again.

Is there a way to put a timeout on the execution of a function or line of
VBA code. I guess this could help in the event that a function has an
infinite Do...Loop in it by mistake, you could say if the value is not
determined/returned after X amount of time, return an invalid value.
 
J

JLGWhiz

Here is a delay macro that will pause your executing macro but allow
everthing else to run during the delay. You can set the time in tents of
seconds or whole seconds by changing the numbe on line: s = Timer ?

Public Function HalfSecDly()
s = Timer + 0.5
Do While Timer < s
DoEvents
Loop
End Function

You could set it with an If...Then statement for control. I would say give
it 10 seconds, then abort and try later.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top