VB if statement based on minutes of the hour

Soldato
Joined
25 Jul 2006
Posts
3,529
Location
Taunton
need to write an if statement that will run a routine when it gets to a certain minute every hour, surely this is possible i just cant figure it :confused:

what i got:
Code:
If Minutes = 43 Then
Check1.Value = 1
Form1.Show
mnuTrayDoStuff.Checked = True
End If

but that doesnt work, the timer is set to count in intervals of 60000 (1 minute)

any help?
 
does this show the form ever? I also dont understand what you mean about the timer....is it used to run this if statement every minute to check if its the right minute? or do you mean the timer counts up and when its at 43 mins it should trigger? If you could post a bit more of your code I may be able to help more.
 
Last edited:
Ladforce said:
does this show the form ever? I also dont understand what you mean about the timer....is it used to run this if statement every minute to check if its the right minute? or do you mean the timer counts up and when its at 43 mins it should trigger? If you could post a bit more of your code I may be able to help more.
sorry i should have been clearer. its runs once every 60 seconds to check what minute of the hour it is and when its 43 minutes past the hour it runs the code and it shows the form when its 43 minutes past the hour.

noob said:
and thats not what im looking for thats a counter. what i want is something that can look at the system clock and when it recognises that the minutes is at 43 it then runs a routine.
 
Last edited:
What is 'Minutes'?
AFAIK that's not a VB keyword at all.
To get the number of minutes past the hour use
Code:
Minute(Now)
This begs the question, why does your code not error on compile with the use of your undeclared (I assume) Minutes variable? If it is declared then we need to see what you're assigning to it.
Have you got Option Explicit turned on? If not, for God's sake turn it on as it will stop problems like this.

Also for your checkbox you should really use the constant vbChecked and not 1 as this makes things a bit clearer.

Lastly I should also point out that what you're doing isn't a particularly good way to go about things.
The VB timer isn't guaranteed to be accurate and you could well end up with the event firing at hh:42:59 and then at hh:44:00 and you completely missing your window.
 
Last edited:
i love you!

Code:
Minute(Now)
works lovely, and i wouldnt worry too much, its a stupid little project to remind me to do something at 55 past the hour, its nothing special.

and the thing is that it only checks once a minute, and if it doesnt match then it doesnt run the routine.
 
Last edited:
Back
Top Bottom