timer

S

sam

I'm wondering how I might go about setting up a timer. I
want to record the start time and end time of a phone
call from clicking a cmd button which is easy enough but
on the form i want to show the duration. I need to
display a timer which re-sets/starts when the start
button is clicked and stops when the end button is
clicked. Anyone have an idea of how to set this up?
 
N

Nikos Yannacopoulos

Sam,

I have something similar which uses a single command button to start / stop
/ reset. It is pretty easy to make simple additions to the code to also
record start and stop times.
I use the form's timer event, interval 100 (0.1 seconds for higher accuracy)
to run the following code:

Private Sub Form_Timer()
duration = duration + 0.1
If Me.Command0.Caption = "Stop" Then
If duration Mod 1 = 0 Then Me.Text1 = Format(duration / 86400,
"hh:nn:ss")
End If
End Sub

where duration is declared as a public variable type Double.

I use the following code fired off my command button:

Private Sub Command0_Click()
Select Case Me.Command0.Caption
Case "Start"
duration = 0
Me.Command0.ForeColor = vbRed
Me.Command0.Caption = "Stop"
Me.Text1 = "00:00:00"
'code to record start time here
Case "Stop"
Me.Command0.ForeColor = vbBlack
Me.Command0.Caption = "Reset"
'code to record end time here
Case "Reset"
Me.Command0.ForeColor = vbBlue
Me.Command0.Caption = "Start"
Me.Text1 = Null
End Select

End Sub

Names: command button "Command0", duration display text box "Text1".
Substitute as appropriate.

HTH,
Nikos
 
S

sam

-----Original Message-----
Sam,

I have something similar which uses a single command button to start / stop
/ reset. It is pretty easy to make simple additions to the code to also
record start and stop times.
I use the form's timer event, interval 100 (0.1 seconds for higher accuracy)
to run the following code:

Private Sub Form_Timer()
duration = duration + 0.1
If Me.Command0.Caption = "Stop" Then
If duration Mod 1 = 0 Then Me.Text1 = Format (duration / 86400,
"hh:nn:ss")
End If
End Sub

where duration is declared as a public variable type Double.

I use the following code fired off my command button:

Private Sub Command0_Click()
Select Case Me.Command0.Caption
Case "Start"
duration = 0
Me.Command0.ForeColor = vbRed
Me.Command0.Caption = "Stop"
Me.Text1 = "00:00:00"
'code to record start time here
Case "Stop"
Me.Command0.ForeColor = vbBlack
Me.Command0.Caption = "Reset"
'code to record end time here
Case "Reset"
Me.Command0.ForeColor = vbBlue
Me.Command0.Caption = "Start"
Me.Text1 = Null
End Select

End Sub

Names: command button "Command0", duration display text box "Text1".
Substitute as appropriate.

HTH,
Nikos




.
 
S

sam

There is one problem which i don't know how to overcome,
you can't use a combo box on the form with the timer
running.
 
N

Nikos Yannacopoulos

Sam,

I suspect that amy be because of the too small interval (100msec) the timer
is set to. I have a form with a 1 sec timer interval with many combos on it,
and no problem! Maybe changing the timer interval to 1 sec (and modifying
the code accordingly) would solve it, with a small sacrifice in the duration
accuracy (errors of +/- 1 sec max., istead of current +/- 0.1 sec).
If that doesn't work, then you might need to put your timer on a separate
form, though I'm not certain this is the answer!

HTH,
Nikos
 

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

Similar Threads


Top