Increase the time by 1 second

accessman2

Registered User.
Local time
Yesterday, 17:14
Joined
Sep 15, 2005
Messages
335
Hi,

I have a question.

I want to make a action on every 2 hours on the form.

On form time interval, I set 1000

Private Sub Form_Open()
a = "00:00:00"
End Sub

Private Sub Form_Timer()
On Error GoTo Err_mess
timelabel = CDate(a) + cdate("00:00:01")

Err_mess:

End Sub


I want to start 00:00:00, and then add 1 second on every time interval=1000.

eg.
00:00:00
00:00:01
00:00:02
00:00:03
...
...
01:00:00

How can I make it? Thanks.
 
We can not rely on the opening time of a Form.
We should set the initial Timer Interval to 1 millisecond.
The Timer will not fire until 1 millisecond after the Form is visible.
The Timer will not fire during almost any other activity, hold a mouse button down and watch it stop.
We can use the API function timeGetTime to the time interval during delays.

The following routine uses the API function to keep track of the time from opening.
The Timer Event simply initiates a screen update of the elapsed time.
If there is a delay, during screen update times, it will still display the correct time.

Code:
Option Explicit
Option Compare Text


Private Declare Function timeGetTime Lib "Winmm.dll" () As Long


Private Sub Form_Timer()
    Static blnInitialized  As Boolean  [color=green]' Defaults to 0 (Zero, False) on Form Open.[/color]
    Static lngFormOpenTime As Long     [color=green]' Will hold the Form Open Time.
    
    '   On first pass of the timer event the Interval was set to 1 millisecond.
    '   If first pass of the timer event...
    '       Block further initialization attempts.
    '       Set interval to 1000 milliseconds.
    '       Save the starting time.[/color]
    If Not blnInitialized Then
        blnInitialized = True
        Me.TimerInterval = 1000
        lngFormOpenTime = timeGetTime()
    End If

    [color=green]'   Assuming 'timelabel' is a label, change the caption to the 'time from opening'.[/color]
    Me.lblTimeLabel.Caption = Format(CDate((timeGetTime() - lngFormOpenTime) / 86400000), "hh:nn:ss")
    
End Sub

No testing has been done to see what happens if the Form is open for more than 24 hours.

Hope that helps.

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom