Solved

# TIMER

Posted on 1999-11-21
Medium Priority
168 Views
WELL I WANT THAT IF I LOGIN AT 10:00:00 THEN AFTER 30 MIN IE 10:30:00 IT SHOULD GIVE ME A MSG BOX AND SAY 30 MIN

THEN AT 11:00:00 IT SHOULD SAY 60 MINUTES
IN SHORT I WANT THAT AFTER EVERY 30 MIN IT SHOULD GIVE ME A REMAINDER

THANKS SONAL
0
Question by:sonalchouhan
• 3
• 3
• 3
• +2

LVL 2

Expert Comment

ID: 2224318
Put a timer on your form and set its .Interval property to e.g. 60000 msec.

Private Sub Timer1_Timer()
If Format(Time, "nn") = 30 Then

End If
End Sub

Oh, pls don't shout...    ;-)
0

LVL 7

Expert Comment

ID: 2224322
Put a timer on your form, set the Interval to 60000 (that's 1 min). And then put code like this into the Timer1_Interval event

Static Ticks As Integer
Ticks = Ticks + 1

If (Ticks = 30) Then
Msgbox "You moron. 30 mins (again!)"
Ticks = 0
End If

You can't set the timer interval to 60000 x 30 because the timer interval has a maximum value at aprox. 65000.
0

LVL 3

Expert Comment

ID: 2224882
A simple curiosity: ¿why people does not like to use IF's with the in-line fashion? Look:

If Format(Time, "nn") = 30 Then
End If

¿Don't you find this way easier (and shorter)?:

If Format(Time, "nn") = 30 Then MsgBox "Your message..."

Of course, not always that is possible (as when there are A LOT of commands to hang of a THEN branch), but I do each time I can. ¿Am I a dinosaur?
0

LVL 2

Expert Comment

ID: 2224944
Writing complex if-then-else structures is more readable without the "in-line fashion look"...
0

LVL 12

Expert Comment

ID: 2225330
vikiing, I agree with you. I put single item if's on one line. To me it's shorter & cleaner.

It may also be *faster* (haven't checked so this isn't gospel) but in the "old" (pre-VB) days you could help the compiler to optimize the code by intelligent grouping. By putting the IF on one line the compiler knows that there is not going to be a long block of text or ELSE clauses and it may be able to optimize better than if it has to scan ahead looking for the rest of the statement.

M
0

LVL 3

Expert Comment

ID: 2228170

That's the EXACT solution for you !!
0

Accepted Solution

eyaltil earned 20 total points
ID: 2228245
0

LVL 12

Expert Comment

ID: 2230275
Vikiing,

Actually SLE's answer is NOT a 100% "exact" solution. It will NOT give you an ELAPSED time indicator of 30 minutes unless you trigger it at the top of the hour. It's watching for the minutes to be = 30 and if you start the process at 31 past it'll not fire again for 59 minutes. This is fine if you are programming a cookoo clock and you want the noise to trigger on the 1/2 hour, but if you're wanting to chime after an *elapsed* 30 minutes, it doesn't work.

VbMaster's answer will fire the event 30 minutes after you start no matter what time you start at.

Being the lazy type the one change I would make to vbMaster's code is:

Ticks = ( Ticks + 1 ) mod 30

If (Ticks = 0) Then Msgbox "You moron. 30 mins (again!)"

This is shorter and automatically recycles the TICKS variable.

M

0

LVL 2

Expert Comment

ID: 2230496
mark2150 is right - stupid me    ;-)
0

LVL 12

Expert Comment

ID: 2231112
Also I don't see an *answer* posted by eyaltil! He's a *POINT GRABBER*!

sonalchouhan, be sure to REJECT eyaltil's non-answer and give the points to vbMaster!

M
0

LVL 3

Expert Comment

ID: 2234162
>>It will NOT give you an ELAPSED time indicator of 30 minutes

>>VbMaster's answer will fire the event 30 minutes after you start no matter

You're right; I've just noticed the difference.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
###### Suggested Courses
Course of the Month3 days, 4 hours left to enroll