i need to perform a task at a certain time using the using the user inputted Hour and Minute.
I'm thinking of something like using some sort of loop that every time it loops, checks if the Now().Hour
matches HourChoice
and the Now().Minute
matches the MinuteChoice
In this, i also have a user option to chose "AM" or "PM", and if TimeOfDay = "PM"
, add 12 hours (The Now().Hour
is military time).
EDIT:I only want this to run once at a time, not every day.
Best Answer
You could use a
System.Threading.Timer
to do this. Instead of a loop that constantly runs and sleeps, you could set the interval to theTimer
to be the difference between now and the selected time and theTimerCallback
to be theSub
that does the task work. Setting the timeout to 0 orTimeout.Infinite
will make sure this is only executed once.EDIT: Example
Then you just need a Sub to do your task: