Understanding Timer Pause Code


O

Owl

I could have sworn I put this in, but no Search is revealing it, so here it
is (again?).

I have created the following Event Procedure for On Timer (the Timer
Interval is set to 10000):

Private Sub Form_Timer()

'On the forms timer event close the start-up form
DoCmd.Close acForm, "Diana'sStartUpForm"
'Open up the main switchboard form when the start-up form closes
DoCmd.OpenForm "Switchboard"

End Sub

I have subsequently created a Pause Button called Pause This Screen with the
following Event Procedure (which I don’t understand but copied it from the
Internet and modified it where I THOUGHT it needed to be modified to pause
for 30 seconds):

Private Sub Pause_this_screen_Click()
Dim PauseTime, Start, Finish, TotalTime
If (MsgBox("Pause this screen", _
4)) = vbYes Then
PauseTime = 30000 ' Set duration.
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime
DoEvents ' Yield to other processes.
Loop
Finish = Timer ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End
End If

End Sub

My first question is: What does the _4 mean?
My second question is: What do I need to do to modify the screen to pause
for 30 seconds?
My third question is: Does that mean it will pause for 30 seconds IN
ADDITION TO – or INSTEAD OF - the original 10 seconds as set on the timer?

I have added a “Continue to Main Menu†button which overrides the pause, but
would like the pause to be long enough to make the user have control of how
much time is spent on the StartUp screen.

Thank you for any help

Owl
 
Ad

Advertisements

M

Mike B

The code you copied is shown in the Access Help File, but it is more
appropriate to VBScript as the variables are not typed, thence they are
Variants.
The 4 is the constant for the type of msgbox.
If you look at the msgbox function in help, you will see a list of constants
like vbQuestion, vbInformation, etc.

You might have better luck with the following as the timer function returns
Seconds and tenths, not milliseconds, so your pause time would be 30 not
30000.
Since the Timer is a function, I have displayed it as Timer() for clarity.

You can mix the constants in the MsgBox function / procedure to set the type
of message box, the buttons used and which button will be the default
button, all found in the helpfule.


Private Sub Pause_this_screen_Click()
Dim PauseTime As Single
Dim Start As Integer
Dim Finish As Integer
Dim TotalTime As Integer

'Debug.Print CStr(Timer())
If (MsgBox("Pause this screen", vbYesNo + vbQuestion, "Pause Screen")) =
vbYes Then
PauseTime = 30 ' Set duration.
Start = Timer() ' Set start time.
Do While Timer() < (Start + PauseTime)
DoEvents ' Yield to other processes.
Loop
Finish = Timer() ' Set end time.
TotalTime = Finish - Start ' Calculate total time.
MsgBox "Paused for " & TotalTime & " seconds"
Else
End If
End Sub
 
J

John W. Vinson

the timer function returns
Seconds and tenths, not milliseconds

ummm... Mike, I think you're mistaken; it is milliseconds: from the VBA Help -

You can use the TimerInterval property to specify the interval, in
milliseconds, between Timer events on a form. Read/write Long.
 
M

Mike B

It must default to what I said. I tested it before posting. I haven't used
the timer function in VBA to tell the truth, for a very long time. The
first time I ran it I had the time to run set to 30000 expecting
milliseconds and it never timed out, so I added a couple debug.prints to see
what was happening, and it was in seconds and tenths, FWIW.
 
M

Mike B

Further, the timer function isn't the same as the timer object. Just for
Sh*ts and Giggles, I did look in the AC2007 help and under Remarks:

Remarks
In Microsoft Windows the Timer function returns fractional portions of a
second. On the Macintosh, timer resolution is one second.

The timer function is what you would use in a module where it isn't hosted
by a form or report. If you want finer resolution in a module, then you can
go to the windows API and use the multimedia timer. I use it all the time
in Delphi. If you want just milliseconds, you can also use the API Sleep()
function.
 
J

John W. Vinson

Further, the timer function isn't the same as the timer object. Just for
Sh*ts and Giggles, I did look in the AC2007 help and under Remarks:

Sorry, Mike! That was indeed the source of my confusion, and probably Owl's
confusion as well: his code was using BOTH the form's Timer property (which is
in milliseconds) and *also* the VBA Timer function. It's disquieting that
Access includes two quite different features with the same name; I had used
the Form Timer but not the Timer() function. Thanks for the heads-up!
 
Ad

Advertisements

M

Mike B

John W. Vinson said:
Sorry, Mike! That was indeed the source of my confusion, and probably
Owl's
confusion as well: his code was using BOTH the form's Timer property
(which is
in milliseconds) and *also* the VBA Timer function. It's disquieting that
Access includes two quite different features with the same name; I had
used
the Form Timer but not the Timer() function. Thanks for the heads-up!

That was the reason I used the parens after the Timer function statement
for clarity. At my age (I am a 1944 model), I need as much clarity as I can
muster.. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top