#1   Report Post  
Posted to microsoft.public.excel.programming
KT KT is offline
external usenet poster
 
Posts: 47
Default 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??
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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??


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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??

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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??


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
time delay RobcPettit[_2_] Excel Programming 3 September 4th 06 03:39 PM
Time delay function quartz[_2_] Excel Programming 4 November 10th 04 10:10 PM
Time Delay in VBA John Tolman[_2_] Excel Programming 3 October 27th 04 12:05 AM
Copy/Time Delay Mike Excel Programming 6 October 19th 04 02:26 PM
Time Delay Kilcup[_9_] Excel Programming 3 July 2nd 04 03:39 PM


All times are GMT +1. The time now is 04:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"