-
Is there a better way to automatically execute a procedure as the time specified by the application user ? I was thinking of using the timer to check the system time and compare to the time set by the user (my project will try to give the user to set instead of hard coded) to execute......I know it sounds silly...........
-
That's how I do it
I have a textbox that the user keys in the time to start the process. I use a timer to check the system time and when it matches the time in the textbox, the process begins.
Code:
Private Sub Timer1_Timer()
Dim dTmp As Date
On Error Resume Next
Timer1.Enabled = False
If Trim$(txtTime.Text) <> "" Then
dTmp = CDate(txtTime.Text)
If Format(Now, "HH:NN:SS AMPM") = Format(dTmp, "HH:NN:SS AMPM") Then
' Do your stuff here
End If
End If
Timer1.Enabled = True
End Sub
-
Does this mean the program has to keep looking at the system time .......? Will takes up the system resource ? I was wondenring is there a function in the system that will wakes up this .........
-
<?>
Depends on what you are doing but this is a pause function
Code:
'pause for a 5 second interval
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Private Sub Pause(Interval As Long)
Start = GetTickCount
Do While GetTickCount < Start + Interval
DoEvents
Loop
End Sub
'event code
Pause 5000 'Pause for 5 seconds
-
The pause is fine for most things, but a little heavy for time critical situations (notice how the CPU time shoots up to max when you use Doevents like that). In time critical situations, the Sleep API can replace the DoEvents.
As far as scheduling a command for a given time, the Timer control as described by jbart is not all that heavy on resources. If you are just checking the system time every second, or even every half second, it will not make a difference. In fact, you dont have to Disable and Enable the timer each time.
If you are going to do LOTS of processing every tenth of a second, then it might be a bit heavy.
Shrog