Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
JLG, Strange that mine wouldn't work for you. The solution suggested by
Chip is surely much more accurate, delay-wise, but I liked mine because it's so darned simple. It's maybe the Do Events that's causing the problem (?). You could rem out that line and try again. Or/and put it in a new file and try it by itself. It seems to work surprisingly well for me. Cheers, James "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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
James, yours did work after Tom gave me the clue to how I could apply it. My
old brain just don't grasp things like it used to. I sort of have to be led by the hand. Happy hoidays! John "Zone" wrote: JLG, Strange that mine wouldn't work for you. The solution suggested by Chip is surely much more accurate, delay-wise, but I liked mine because it's so darned simple. It's maybe the Do Events that's causing the problem (?). You could rem out that line and try again. Or/and put it in a new file and try it by itself. It seems to work surprisingly well for me. Cheers, James "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 |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Wait Seconds and Tenths
John, Terrific! Lets me know that it's not just a fluke that it's
working on my machine. Best regards for the new year, James JLGWhiz wrote: James, yours did work after Tom gave me the clue to how I could apply it. My old brain just don't grasp things like it used to. I sort of have to be led by the hand. Happy hoidays! John "Zone" wrote: JLG, Strange that mine wouldn't work for you. The solution suggested by Chip is surely much more accurate, delay-wise, but I liked mine because it's so darned simple. It's maybe the Do Events that's causing the problem (?). You could rem out that line and try again. Or/and put it in a new file and try it by itself. It seems to work surprisingly well for me. Cheers, James "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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
sendkeys(keys,wait) how do I use wait | Excel Discussion (Misc queries) | |||
Macro wait 30 seconds then Complete the Macro | Excel Discussion (Misc queries) | |||
Wait Seconds and Tenths | Excel Programming | |||
Display MsgBox wait for 10 seconds then click on yes automatically | Excel Programming | |||
Average time for a race in minutes seconds & tenths | Excel Worksheet Functions |