ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   time delay (https://www.excelbanter.com/excel-programming/374374-time-delay.html)

KT

time delay
 
i would like to make a counter in a text field which count automatically from
1 to 100 when load
how can i make a time delay of 0.5sec between each count??

Incidental

time delay
 
Try this

Insert into a new Module

Sub Every5Secs()
Application.OnTime Now + TimeValue("00:00:05"), "add1"
End Sub

Sub add1()
UserForm1.TextBox1 = UserForm1.TextBox1 + 1
If UserForm1.TextBox1 = 100 Then
MsgBox "That's 100"
Exit Sub
End If
Call Every5Secs
End Sub

Create a userform with one textbox leave the names at default insert
this code

Private Sub UserForm_Initialize()
Call Every5Secs
TextBox1 = 1
End Sub

Then run the form

Hope this is of some help

S

KT wrote:
i would like to make a counter in a text field which count automatically from
1 to 100 when load
how can i make a time delay of 0.5sec between each count??



JLGWhiz

time delay
 
I wish you luck. I have been trying to find a way to get less than one
second delay for a long time. I am not sure it is possible in VBA.

"KT" wrote:

i would like to make a counter in a text field which count automatically from
1 to 100 when load
how can i make a time delay of 0.5sec between each count??


Incidental

time delay
 
There is a reason i own glasses doh!!!!

sorry didin't see that decimal point in the original post.
not sure how to get a time less than a second sorry

S

KT wrote:
i would like to make a counter in a text field which count automatically from
1 to 100 when load
how can i make a time delay of 0.5sec between each count??



Incidental

time delay
 
Hi back again, was feeling bad about not reading your post correctly
the first time round. I had a search through the groups and have come
up with this, which probably won't solve your problem but it may help
you figure out what to do...

After trying a few different methods I came across a snippet posted by
Ray McCoppin back in April of this year, which is a fantastic little
bit of code that I shall be keeping in mind myself.

I couldn't get this to work on a userform but it seems to work just
fine on a worksheet.

Create a userform with a command button on it then add this code

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub CommandButton1_Click()
[A2] = Time 'show start time
Call sleepy
End Sub

Private Sub Add1()
[A1] = [A1] + 1
If [A1] = 100 Then
[A3] = Time 'show finish time
Exit Sub
Else
Call sleepy
End If
End Sub

Private Sub UserForm_Initialize()
[A1] = 1 'number to start count
End Sub

Private Sub sleepy()
Sleep 500 'set amount of milliseconds delay here
Call Add1
End Sub

By my count if you count 1 to 100 with a half second between each count
it should take you 50 seconds (shouldn't it?? LoL) well this will do
just that.

I hope it helps you out and again I'm sorry for not reading your post
properly the first time round.

S



All times are GMT +1. The time now is 08:32 AM.

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