View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Wait Seconds and Tenths

Thanks, Tom. Old Codgers can learn new tricks. I was trying to nest the
wrong kind of loop. Never tried the DoEvents thing before.

And Zone, glad you got yours working too.

Merry Crhistmas to all.

John

"Tom Ogilvy" wrote:

Sub EFG()
Dim counter As Long
Dim s As Single
counter = 1
Do Until counter = 37
MyClrValue = Int((55 * Rnd) + 1)
With Worksheets(2)
.Range(.Cells(counter, 1), _
.Cells(counter, 16)).Interior _
.ColorIndex = MyClrValue
End With
s = Timer + 0.5
Do While Timer < s
DoEvents
Loop
'Here is where I need about a half second,
'or maybe quarter second delay.

counter = counter + 1
Loop

End Sub


worked on my machine. Can't say it waits exactly half a second, but there
is a measurable pause.

--
Regards,
Tom Ogilvy


"JLGWhiz" wrote in message
...
Zone, couldn't get yours to work with my application:

Counter = 1
Do Until Counter = 37
MyClrValue = Int((55 * Rnd) + 1)
Worksheets(2).Range(Cells(Counter, 1), Cells(Counter,
16)).Interior.ColorIndex = MyClrValue
'Here is where I need about a half second,
'or maybe quarter second delay.
Counter = Counter + 1
Loop

Without the delay it looks like all the colors appear at once and I want
the
waterfall effect.

"Zone" wrote:

Thanks, Chip. Even better! James
"Chip Pearson" wrote in message
...
Zone,

Try the following code:

Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub FallAsleep()
Dim Seconds As Long
Dim Tenths As Long
Dim SleepTime As Double
Seconds = Range("A1").Value
Tenths = Range("B1").Value
SleepTime = ((Seconds * 1000) + (Tenths * 100))
Debug.Print "Ready To Sleep: " & CStr(SleepTime)
Sleep dwMilliseconds:=SleepTime
Debug.Print "Wake Up"
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Zone" wrote in message
ps.com...
I want to put a whole number in a cell, say A1, to represent seconds,
and another whole number in a cell, say B1, to represent tenths (or
hundredths) of a second. How do I get my macro to pause for this
amount of time? Please specify type of any variables! Thanks, James