ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Visual Basic Timer (https://www.excelbanter.com/excel-programming/374721-visual-basic-timer.html)

Jay

Visual Basic Timer
 
I need to run a certain code for 5 seconds. (i.e. a DC motor hooked @ a
certain speed). I assumed I would be able to use a "do while" loop and the
=now(time) function but cannot seem to get it to work. Any tips?
Thanks!

Dave Patrick

Visual Basic Timer
 
Try something like this.

Dim mytime As Date
Dim mydelay As Single
Dim myseconds As Integer
myseconds = 5
If myseconds 0 Then
mydelay = myseconds / 86400
Else
Exit Sub
End If
mytime = Now()
Do While Now() < mytime + mydelay
DoEvents
Loop

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Jay" wrote:
|I need to run a certain code for 5 seconds. (i.e. a DC motor hooked @ a
| certain speed). I assumed I would be able to use a "do while" loop and the
| =now(time) function but cannot seem to get it to work. Any tips?
| Thanks!




All times are GMT +1. The time now is 02:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com