N00b Question SetTimer KillTimer
I've read everything in all the api post, but haven't found what i am looking for. I have designed some hardware for LPT and wish to control all 12 outputs. So i need to write a schedule that starts ie. at 13:30 finishes at 16:45 has the option to run for x seconds/minutes and wait x seconds/minutes (toggle) using user input through "Text boxes". Can someone please give me an example that also makes the toggle function optional. I have been learning for a week, and am stuck, I already know the arguments for setTimer/killTimer i just need an example. pls
Re: N00b Question SetTimer KillTimer
vb Code:
Private Sub Timer1_Timer()
If Now > DateValue(txtDate.Text) + TimeValue(txtTime.Text) Then
' Do the function i need
txtDate.Text = Format$(Date + 1, "dd/mm/yy")
txtTime.Text = "23:00:00"
End If
End Sub
Worked it out, just want to know if the inbuilt timer is just as reliable as the api ? which is better ?
Re: N00b Question SetTimer KillTimer
The VB Timer control is not known for its accuracy so I would stick with your API solution.
Re: N00b Question SetTimer KillTimer
Hmmm...
I Don't have an api solution, only a resounding question..
Re: N00b Question SetTimer KillTimer
Quote:
Originally Posted by Harvey.Keitel
I Don't have an api solution, only a resounding question..
:confused: Your quote below indicated to me that the issue had been resolved.
Quote:
Originally Posted by Harvey.Keitel
Worked it out, just want to know if the inbuilt timer is just as reliable as the api ? which is better ?
If this is not so, then what did you work out, and what is the remaining question?
Re: N00b Question SetTimer KillTimer
Sorry..
I worked out how to do a schedule using the inbuilt timer only, can not find any examples with google for "Timer API" just the procedures and syntax, but not much else. I wish to find an example using the API , but wasn't sure of the accuracy of the VB Timer in the first instance.
Can you or someone please just show me some meat ? Just the basics of setting the start time and the end time. And i should be able to work the rest out by myself.
Re: N00b Question SetTimer KillTimer
Re: N00b Question SetTimer KillTimer
Thanx for trying, look at examples before, show you how to set a timer length (That i understand) and kill the timer (For a specified length) , but i wish to set a DATE/TIME for when an execution should begin and a DATE/TIME for when the schedule should end using the API. They are many places that talk about the WM_Timer / Timer API / and seeing such things as localtime(). I just wish to see a few or at least one example for setting a Specific Date+Time start and end.
Re: N00b Question SetTimer KillTimer
Setting up something like this would require the both the process running it and the machine running it to be up 24/7
This almost sounds like you would need to create a Service which can be fairly complicated.
How often, and when, would you need this to run?
Re: N00b Question SetTimer KillTimer
24/7, already know how to setup service.
Re: N00b Question SetTimer KillTimer
Not being rude.. Is there a way to set a specific date/time ? I just wish to see an example, and nothing else. OK ?
Re: N00b Question SetTimer KillTimer
An API timer is just a better (IMO) version of the normal timer control. If the code you have in the timer control in post #2 works ok, then simply put it in the callback function of an API timer.
EDIT: I don't think there's an API that will perform an action at a specific time automatically - you have to write the function to poll the (system) time, as per your post #2.
Re: N00b Question SetTimer KillTimer
The code in Post #2 works fine, i'm not sure how to do that... Can you point me to a working example or show me how ? I almost have given up and wrote to a few programmers to see if i can persuade them (pay $$$). But your input is highly valued regardless.
Re: N00b Question SetTimer KillTimer
vb Code:
Option Explicit
'Form level code.
Private Sub Form_Load()
Call StartTimer
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call KillTimer(0&, intTimerID)
End Sub
vb Code:
Option Explicit
'Module level code.
'Timer APIs. Allow events of @ 25 days.
Public Declare Function SetTimer Lib "user32.dll" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32.dll" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
'Timer identifier.
Public intTimerID As Long
Private Const TIMEOUT As Long = 5000 'Test - 5 seconds.
'For 4 hours this would be: 4 x 60 x 60 x 1000 = 14400000
'Can be up to 2147483647 (a Long)
Public Sub StartTimer()
'Create the timer.
intTimerID = SetTimer(0&, 0&, TIMEOUT, AddressOf MyTimer)
End Sub
Private Sub MyTimer(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
'This callback sub MUST be in a module.
'Do your stuff
MsgBox "Hello World"
'Destroy the timer - IF you only want a SINGLE event.
'----------------------------------------------------
'You don't HAVE to do this right away, but you MUST
'do it before you unload your application.
Call KillTimer(0&, intTimerID)
End Sub
In "Private Sub MyTimer(...)", just substitute your code for [MsgBox "Hello World"] . Just as obviously, if this has to run 24/7, remove the line "Call KillTimer(0&, intTimerID)". Set "Private Const TIMEOUT" to whatever interval suits.
Quote:
Originally Posted by Harvey.Keitel
I almost have given up and wrote to a few programmers to see if i can persuade them (pay $$$).
You owe me $100. ;)
Re: N00b Question SetTimer KillTimer
Cheers Bro, that worked a treat. I guess this thread is finished...
Where do you want me to send the money ?
Re: N00b Question SetTimer KillTimer
Quote:
Originally Posted by Harvey.Keitel
Where do you want me to send the money ?
I wish :wave: