[AccessD] Elapsed time class - Stuart please ignore...

Rocky Smolin rockysmolin at bchacc.com
Sat Jul 16 09:10:25 CDT 2011


Ooh, I could that.  Can I get a copy when it's ready?

Sign me,

Living With a StarCraft Addict

(Rocky)


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of jwcolby
Sent: Saturday, July 16, 2011 6:35 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] Elapsed time class - Stuart please ignore...

I'm building a little database to time / log my son's computer time.  I have
a form which he uses to 
select a game which opens the game for him, creates a record in the table
and starts the timer, 
leaving this form up in the background behind the game.  As he closes the
game the form becomes 
visible and he clicks a button to update the stop time in the table and
stops the elapsed time timer.

Not yet done, I will be causing the form to beep at him as he goes over the
allotted time to play 
the game.

Nothing special here, just wrapping the code / date I needed to measure
elapsed time into a class. 
Obviously the point of putting it in a class is that it can be used in one
or a hundred forms to 
perform elapsed time calcs, and it carves out all of that data / logic into
a single place.

To use it in any form just dimension a variable and set it to a new instance
of the variable:

Dim mcElapsedTime As clsElapsedTime

Private Sub Form_Open(Cancel As Integer)
     Set mcElapsedTime = New clsElapsedTime
     Me.TimerInterval = 1000	- set up the timer for one second timer
ticks
End Sub

Private Sub Form_Timer()
     mcElapsedTime.UpdateElapsedTime
     txtElapsedTime = mcElapsedTime.pElapsedTime
End Sub



The elapsed time class:

Option Compare Database
Option Explicit

Private mlngSeconds As Long
Private mlngMinutes As Long
Private mlngHours As Long
Private mstrElapsedTime

Property Get pElapsedTime() As String
     pElapsedTime = mstrElapsedTime
End Property
Property Get pSeconds() As Long
     pSeconds = mlngSeconds
End Property
Property Get pMinutes() As Long
     pMinutes = mlngMinutes
End Property
Property Get pHours() As Long
     pHours = mlngHours
End Property

Private Function CalcElapsedTime()
     mstrElapsedTime = mlngHours & ":" & mlngMinutes & ":" & mlngSeconds
End Function
Function mResetElapsedTime()
     mlngSeconds = 0
     mlngMinutes = 0
     mlngHours = 0
End Function
Function UpdateElapsedTime()
     mlngSeconds = mlngSeconds + 1
     If mlngSeconds >= 60 Then
         mlngSeconds = 0
         mlngMinutes = mlngMinutes + 1
     End If
     If mlngMinutes >= 60 Then
         mlngMinutes = 0
         mlngHours = mlngHours + 1
     End If
     CalcElapsedTime
End Function

-- 
John W. Colby
www.ColbyConsulting.com
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list