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
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 IfEnd Sub
This was the error, not sure if you can ready what is says Compile Error: Type Mismatch
Richard Phillips said:Dim Timer() As Single ' Added trying to stop the Subscript out of range (Error9) ' modified to as Single 081619
You have to learn the difference between variable and function. You try to define the function 'Timer()' as variable. this could not work.
Just throw the quoted line out, and the sample works. :-)
And please!!!!! use 'insert'-> '</>insert code'. It is so much easier to read the code if it is well formatted.
Mit freundlichen Grüßen / Best regards Volker Hüfner
| AB_DATE Engineering Software | ab-date.de |
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:
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.
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 :-)