See Also Example
Returns the number of seconds that have elapsed since 12:00 A.M. (midnight).
The Timer function is automatically used with the Randomize statement to generate a seed You can also use it to time programs or parts of programs. for the Rnd (random-number) function.
Timer Function Example
The example uses the Timer function to keep track of elapsed time required to find all prime numbers between 1 and 1000. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Const UNMARK = 0, MARKIT = Not UNMARK, MAXNUM = 1000
Static Mark(MAXNUM) ' Set up an array.
Dim Delta, Finish, I, Msg, N, Num, Start ' Declare variables.
Start = Timer ' Set start time.
Num = 0 ' Initialize number counter.
For N = 3 To MAXNUM Step 2 ' Find all primes.
If Not Mark(N) Then
Delta = 2 * N
For I = 3 * N To MAXNUM Step Delta
Mark(I) = MARKIT
Num = Num + 1
Finish = Timer ' Set end time.
Msg = "The program took " & (Finish - Start)
Msg = Msg & " seconds to find "
Msg = Msg & Num & " prime numbers."
MsgBox Msg ' Display message.