Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

count up timer display 1

Status
Not open for further replies.

jerryreeve

Vendor
Jan 16, 2002
2,765
US
I am trying to get two displays on a form, first one is just a clock (txtTimeCount) that is working correctly. second one is a count up timer that displays elapsed time on the form (txtShortCount) I am running into a error 13 type mismatch. it does not like the countup display line.
I am thinking that I will need to format the datatype of txtshortcount to date but that did not help at all.
I have been looking on the forum and microsoft's pages but I just am not seeing the obvious, can you guys give me a steer in the right direction?

thanks

Code:
Private Sub Form_Timer()
Dim TimeCountStart As Date
    
   TimeCountStart = Time$()
   Me.txtTimeCount = Time$() 'Time display
   Me.txtShortCount = Time$() - TimeCountStart 'countup display
   Me.TimerInterval = 1000
End Sub

----------------------------
Hill?? What hill??
I didn't see any $%@#(*$ Hill!!
----------------------------
JerryReeve
Communication Systems Int'l
com-sys.com

 
Time$ is a string.
What happens if you use Time instead ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
that corrected the error but shorttimecount is not counting up it looks like I need to get timecountstart to get the time once and not update itself. I think I can put a text box on the form that gets the time once at startup of form and I can then reference that tie for count, I'll let you know.

----------------------------
Hill?? What hill??
I didn't see any $%@#(*$ Hill!!
----------------------------
JerryReeve
Communication Systems Int'l
com-sys.com

 

That's right, you need to have something to hold the start time that doesn't change, then calculate surrent time against start time.

Another question:

Why do you have Me.TimerInterval = 1000 in the Form_Timer event itself? This would normally be set either in the Form_Load event or in an event that initiates the countdown.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Private Sub Form_Timer()
Static TimeCountStart
If IsNull(TimeCountStart) Then
TimeCountStart = Time
End If
Me!txtTimeCount = Time 'Time display
Me!txtShortCount = Time - TimeCountStart 'countup display
Me.TimerInterval = 1000
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV: OK thanks a ton, end result is:
Code:
Private Sub Form_Timer()
Static TimeCountStart
If TimeCountStart = Empty Then
    TimeCountStart = Time
    End If
   Me!txtTimeCount = Time 'Time display
   Me!txtShortCount = Time - TimeCountStart  'countup display
   Me.TimerInterval = 1000
End Sub
in addition to changing the if statement above (the ifnull command string wouldn't work)I also had to specify to the txtshortcount that the format was nn:ss (interesting, even though I put in mm:ss the properties box changed it to nn:ss)

missinglinq: the form itself is what initiates the countup, when the form is opened the counter starts to indicate to the salesperson roughly how long they have been on a call.

----------------------------
Hill?? What hill??
I didn't see any $%@#(*$ Hill!!
----------------------------
JerryReeve
Communication Systems Int'l
com-sys.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top