-
Hi Guys
Excuse my ignorance, but i am new to VB programming although i am experienced in Access programming.
I am buliding a small VB app to compact and backup Access databases overnight. I have the whole thinking working on a command button at present, and it works weel.
I now want to be able to have it happen at a particular time, probably when i am at home watching the Olympics :-)
Can someone briefly explain the concepts behind the Timer Event? I can set the given time, but i'm not sure how to get my program to check what the time is. In Access, i have to get my code to check the time every 30 minutes or so and compare it to the required time, but isn't this using resources? If i want to backup at say, 23:00, do i have to get my VB app to check the time every minute? Doesn't this mean that the app is grabbing resources almost constantly? I think you get the gist of my ignorance.
Many thanks
Peter Gidden
-
Code:
Dim strTime as String
Private Sub Timer1_Timer ()
strTime = Time
if strTime = TheTimeThatYouWant then
'code for backing up
End If
Set your timers interval to 1000
-
Thanks Dimava
So is this the standard way of doing things? I presume it must be low on resources, cos this will mean the app is checking the time every minute of the day until the stored time.
-
Peter,
Actually the code that Dimava posted will check once each second. The Timer is set using milliseconds. 1000 milliseconds = 1 second.
The Timer interval can go up to 65535 milliseconds, so if you want to you can set the interval to 60000 to check the time once each minute.
I am no expert on operating systems, but as far as using up resources, I do not think that a timer running in the background will cause any significant performance hit.
Your operating system is constantly updating system timers in the background hundreds, if not thousands of times each second anyway. So your program jumping in once each second is just another of numerous processes that are occurring.
-
Hi Peter,
the above code looks for time to reach at every SECOND !!! I think you should be awared that the time interval you set in your timer can't be more than 65535 and that this this interval is in milliseconds...
-
Thanks Guys
So 60000 = 1 minute which should do fine.