I want the timer to set the interval in hours or minutes and not in milliseconds.

I get the following error when I set the interval as in minute as Timer1.Interval = 60000 * 5

"Run-time error 380, Invalid Property Value"

Recommended Answers

All 6 Replies

Sorry dude, but the regular timer cannot take values larger than 65535 ms. So my advise, you can try Long Timer, a freeware program. The link is here
Just scroll down to the download link. Hope this helps.

^ Thanx lalo, u rock :)

Do you know there is a BUG in the Long Timer, please download the attachment and see for youself :)

try using globals parameteres for Hours and Minutes and seconds

global g_Hour as integer 
global g_Minute as integer
global g_Seconds as integer

Set the timer for 1000 ( one seccond )

Private Sub Timer1_Timer()
Dim mySeconds As Integer
Dim MyMinutes As Integer
Dim MyHours As Integer
mySeconds = 21
MyMinutes = 9
MyHours = 2
If g_seconds >= 60 Then
     g_minute = g_minute + 1
     g_seconds = 0
     If g_minutes >= 60 Then
        g_hours = g_hours + 1
        g_minutes = 0
        End If
    End If
If g_hours = MyHours Then
    If g_minutes = MyMinutes Then
        If g_seconds = mySeconds Then
        
        'Action would happen Here
        
        End If
    End If
End If
End Sub

That should work or be pretty close.

I forgot to increment g_seconds. here it is again, working this time.

Private Sub Timer1_Timer()
Dim mySeconds As Integer
Dim MyMinutes As Integer
Dim MyHours As Integer
mySeconds = 11
MyMinutes = 0
MyHours = 0
g_seconds = g_seconds + 1
If g_seconds >= 60 Then
     g_minutes = g_minutes + 1
     g_seconds = 0
     If g_minutes >= 60 Then
        g_Hours = g_Hours + 1
        g_minutes = 0
        End If
    End If
If g_Hours = MyHours Then
    If g_minutes = MyMinutes Then
        If g_seconds = mySeconds Then
        
        'Action would happen Here
        MsgBox "Done"
        g_seconds = 0
        g_minutes = 0
        g_Hours = 0
        
        End If
    End If
End If
Label1.Caption = g_Hours & ":" & g_minutes & ":" & g_seconds
End Sub

I would suggest setting your timer to 60 seconds (1 minute) OR every second. Then keep a variable that gets incremented as the timer fires. Then you can check it for the time in question, and fire it accordingly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.