Solved

Timer

Posted on 2002-06-10
13
320 Views
Last Modified: 2010-05-02
Ok, I forgot how to use a timer as a pause...

Basically, I want to create a three second pause in a procedure to calculate some numbers...doevents just doesn't cut it.

I set the timer interval to 3000 in the load. Then I enable timer?
0
Comment
Question by:Barb0400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 2

Expert Comment

by:mmcmillen
ID: 7067846
yes that shhould do it.   I'm not sure I understand why you want to do that.  What happens if the calcs take longer than the 3 seconds?

maybe putting your calcs in a function would work better.
0
 
LVL 5

Expert Comment

by:rpai
ID: 7067852
Yes, in the Form_load simply set the Timer Interval to 3000.

0
 
LVL 5

Expert Comment

by:rpai
ID: 7067863
..And in the Timer Event do the calcs.

Here's and example:-
Private Sub Form_Load()
Command1.Caption = Time
Timer1.Interval = 3000
End Sub

Private Sub Timer1_Timer()
Command1.Caption = Time
End Sub
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:Barb0400
ID: 7067866
when I set tmrProcessing.enabled = true, I want it to wait 3 seconds before going to the next line...

private sub startcalcs()
    If bCancelCheck Then
        bCancelCheck = False
        bLoading = False
        Exit Sub
    End If
   
    tmrProcessing.Enabled = True
   
     Call DisableTabs
   
     Call DoCalcs

end sub


The timer routine looks like this:



Private Sub tmrProcessing_Timer()
    tmrProcessing.Enabled = False
End Sub
0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 7067883
Hello

  Use the Sleep API, to pause ur code

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Command1_Click()
  MsgBox "Hello"
  Sleep (3000)
  MsgBox "Hello after 3 seconds"
End Sub
0
 
LVL 3

Expert Comment

by:nichia
ID: 7067894
You can use this API function when you need a delay in your program.

The declaration is:

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

The sub program is used as in the following example

Sleep 3000 '// 3 second delay

0
 
LVL 18

Accepted Solution

by:
Crash2100 earned 50 total points
ID: 7067897
Why don't you just do something like this?


'start processing

Dim EndTime As Date
EndTime = DateAdd("s", 3, Date + Time)

Do While Date + Time < EndTime
    DoEvents
Loop

MsgBox "done!"
0
 

Author Comment

by:Barb0400
ID: 7067902
I don't want to use the Sleep API, i just want the previously executed code to catch up...
0
 
LVL 5

Expert Comment

by:rpai
ID: 7067940
Barb0400,
The Timer event would trigger when a preset interval for a Timer control has elapsed (specified in the Interval property).

Something like this might help:-
Private Sub Form_Load()
DoMath
End Sub

Private Sub DoMath()
x = x + 100
Command1.Caption = x & "   " & Time
'-- Pause for 3sec and then proceed with the Math.
Timer1.Interval = 3000
'-- After 3sec the Timer1_Timer event will be triggered
End Sub

Private Sub Timer1_Timer()
'-- Continue with the calculations.
x = x + 100
Command1.Caption = x & "    " & Time
End Sub
0
 
LVL 3

Expert Comment

by:nichia
ID: 7068000
>>"I just want the previously executed code to catch up"

Not sure I understand what you mean.  Which code is not "catching up?"

0
 

Author Comment

by:Barb0400
ID: 7068006
The problem I'm having is when I the user switches tabs. When they hit a tab, the previous tab has to have time to do an "endedit" and a "recalc" before the tab click event actually fires. I just need to put an immediate three second pause in the tabclick event so it can finish calculating the last tab before proceeding. Isn't there a way to have the timer event fire immediately, then wait three seconds and disable it?
0
 
LVL 5

Expert Comment

by:rpai
ID: 7068048
The Timer event would fire after waiting for 3 seconds.

So in the tabclick event specify the Timer1.Interval = 3000
And in the Timer1_Timer Event, specify the name of the function that needs to be performed after 3 seconds pause.
0
 
LVL 3

Expert Comment

by:nichia
ID: 7068094
You can use the _BeforeClick event to do all this processing.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question