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,

    please do not get me wrong. I have a high respect for people trying to lern new stuff by them self. Most of your mistakes / questions showing a great leak of fundamental knowlage.

    VBA is like other program languages really a language. It is not enough to learn how to speak some sentences, and then try to modify them.

    At least you have to know the differences between verbs, subjects and objects, or in VBA between variables, functions, etc. Nice and detail coding comes with time. 

    I would like to recommend you  http://smallbasic.com/ from Microsoft. It is more like a game, with a fun factor, not a dry book-lesson. But after some lessons you know the important basics about variables, function and methods. And I can nearly guarantee you: VBA will look easier to you afterwards :-)

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

Reply
  • Hi Richard,

    please do not get me wrong. I have a high respect for people trying to lern new stuff by them self. Most of your mistakes / questions showing a great leak of fundamental knowlage.

    VBA is like other program languages really a language. It is not enough to learn how to speak some sentences, and then try to modify them.

    At least you have to know the differences between verbs, subjects and objects, or in VBA between variables, functions, etc. Nice and detail coding comes with time. 

    I would like to recommend you  http://smallbasic.com/ from Microsoft. It is more like a game, with a fun factor, not a dry book-lesson. But after some lessons you know the important basics about variables, function and methods. And I can nearly guarantee you: VBA will look easier to you afterwards :-)

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

Children
No Data