Macro to wait ten seconds..?

  • Thread starter Thread starter Gojavid
  • Start date Start date
G

Gojavid

I have some code that maps a network drive using a shell and command
prompt. In the same code it checks if the command was successful or
not. The problem is that it takes a second for command prompt to
create the drive and the macro is already passed the check by the time
it actually maps the drive.

The check I use is:

If dir("mapped drive name")="" then
msgbox("Drive mapping was not successful.")
end if

I was hoping that I could have the macro wait a few seconds before it
checks to see if the drive is mapped. I thought about a loop, but I
didn't want it to continue forever if the drive didn't map.

Any ideas?
 
Gojavid,

The problem with a timeout is that you don't know how long to wait, unless you make it long
enough for worst-case situations, and then it takes longer to run than it ought to. Try
this psuedo-code:

Get start time (StartTzime = Now() )
Test for drive (If dir("mapped drive name")<>"")
No,
Been too long? (test current time against StartTime)
Yes, get out, mapping failed
No,
Go back and test again (with one-second wait if desired)
Yes,
done

--
Earl Kiosterud
www.smokeylake.com

Note: Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
Thank you to both of you!

Gojavid,

The problem with a timeout is that you don't know how long to wait, unless you make it long
enough for worst-case situations, and then it takes longer to run than it ought to. Try
this psuedo-code:

Get start time (StartTzime = Now() )
Test for drive (If dir("mapped drive name")<>"")
No,
Been too long? (test current time against StartTime)
Yes, get out, mapping failed
No,
Go back and test again (with one-second wait if desired)
Yes,
done

--
Earl Kiosterudwww.smokeylake.com

Note: Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
 
Back
Top