Timer() Code failure

I have read a lot of questions, I have also taken advice on the Goggle the question and spent hours trying to get a simple timer

I tried using the Timer() feature but Debug does not like what I have . I called myself copying it correct I had even tried making a Dim Timer just in case.

Will anyone help me figure this out? Please See below tried to paste in the error message received and I read the help on it but still do not know what is wrong

Type mismatch (Error 13) 

is where is read?

Sub PauseCodeOld1()
Dim Start As Single ' Snapshot of when timer started
Dim Elapsed As Single ' Total time elapsed
Dim Pausetime As Single ' Desired duration in seconds
Dim TimerTemp As Single ' store current value of Timer function
Dim Timer() As Single ' Added trying to stop the Subscript out of range (Error9)
' modified to as Single 081619
If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
Pausetime = 5 ' Set duration.
'MsgBox ("Time Now " & Results)

' Store current Timer value
' Timer is a VBA function that Returns a Single representing
' the number of seconds elapsed since midnight.
Start = Timer()

Do ' Begin a Do While Loop
DoEvents ' Yield to other processes and waste time.

' Calculate elapsed time
' Get current value of Timer function
TimerTemp = Timer
' Calculate how many seconds have elapsed between now and Start
Elapsed = TimerTemp - Start
Debug.Print "Elapsed: " & CStr(Elapsed)

' Determine if the Elapsed time is greater than desired pause time
' If not, then repeat loop
Loop While Elapsed <= Pausetime

MsgBox "Paused for " & CStr(Elapsed) & " seconds"
End If
End Sub

This was the error, not sure if you can ready what is says Compile Error: Type Mismatch

Parents
  • Hi Richard,

    The Timer function is a Microsoft VBA function and provides a short clean example to start from.

    Maybe something that can help you review/research something in the Microsoft VBA Editor, would be to place your mouse cursor on a given (class, keyword, type, or) function and try using the F1 function key - that will open either:

    1. The Microsoft VBA help to that specific word, or
    2. If a Bentley MicroStation VBA item open the MicroStation VBA Help File.

    In either case, as long as the keyword is valid using F1 will jump you directly to the respective VBA documentation and most likely provide a code snip/example you can copy and paste to try as-is.  Try it to see it work. Use the Debugger to step through it line by line or set break points to observe and learn what is really happening. And also in the beginning start to make small modifications - one change at a time - until more confident where you can start to perform a couple changes, larger changes and test/verify proper operation before going to far.

    HTH,
    Bob



Reply
  • Hi Richard,

    The Timer function is a Microsoft VBA function and provides a short clean example to start from.

    Maybe something that can help you review/research something in the Microsoft VBA Editor, would be to place your mouse cursor on a given (class, keyword, type, or) function and try using the F1 function key - that will open either:

    1. The Microsoft VBA help to that specific word, or
    2. If a Bentley MicroStation VBA item open the MicroStation VBA Help File.

    In either case, as long as the keyword is valid using F1 will jump you directly to the respective VBA documentation and most likely provide a code snip/example you can copy and paste to try as-is.  Try it to see it work. Use the Debugger to step through it line by line or set break points to observe and learn what is really happening. And also in the beginning start to make small modifications - one change at a time - until more confident where you can start to perform a couple changes, larger changes and test/verify proper operation before going to far.

    HTH,
    Bob



Children
No Data