?
Solved

TIMER

Posted on 1999-11-21
11
Medium Priority
?
168 Views
Last Modified: 2010-05-02
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
Comment
Question by:sonalchouhan
  • 3
  • 3
  • 3
  • +2
11 Comments
 
LVL 2

Expert Comment

by:SLE
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
   
        MsgBox "Here comes your message..."
    End If
End Sub


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

Expert Comment

by:Vbmaster
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

by:vikiing
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
        MsgBox "Your message..."
    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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 2

Expert Comment

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

Expert Comment

by:mark2150
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

by:vikiing
ID: 2228170
Why you've rejected SLE's answer?

That's the EXACT solution for you !!
0
 

Accepted Solution

by:
eyaltil earned 20 total points
ID: 2228245
Answer as above
0
 
LVL 12

Expert Comment

by:mark2150
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

by:SLE
ID: 2230496
mark2150 is right - stupid me    ;-)
0
 
LVL 12

Expert Comment

by:mark2150
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

by:vikiing
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question