|
-
Oct 16th, 2007, 05:27 AM
#1
Thread Starter
New Member
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
-
Oct 17th, 2007, 07:17 AM
#2
Thread Starter
New Member
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 ?
Last edited by Harvey.Keitel; Oct 17th, 2007 at 07:50 AM.
-
Oct 17th, 2007, 07:23 AM
#3
Re: N00b Question SetTimer KillTimer
The VB Timer control is not known for its accuracy so I would stick with your API solution.
-
Oct 17th, 2007, 07:45 AM
#4
Thread Starter
New Member
Re: N00b Question SetTimer KillTimer
Hmmm...
I Don't have an api solution, only a resounding question..
-
Oct 17th, 2007, 08:07 AM
#5
Re: N00b Question SetTimer KillTimer
 Originally Posted by Harvey.Keitel
I Don't have an api solution, only a resounding question..
Your quote below indicated to me that the issue had been resolved.
 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?
-
Oct 17th, 2007, 08:19 AM
#6
Thread Starter
New Member
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.
-
Oct 17th, 2007, 08:48 AM
#7
Re: N00b Question SetTimer KillTimer
-
Oct 17th, 2007, 09:10 AM
#8
Thread Starter
New Member
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.
-
Oct 17th, 2007, 09:37 AM
#9
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?
-
Oct 17th, 2007, 09:38 AM
#10
Thread Starter
New Member
Re: N00b Question SetTimer KillTimer
24/7, already know how to setup service.
Last edited by Harvey.Keitel; Oct 17th, 2007 at 09:44 AM.
Reason: forget some details
-
Oct 17th, 2007, 10:06 AM
#11
Thread Starter
New Member
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 ?
-
Oct 17th, 2007, 11:45 AM
#12
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.
Last edited by schoolbusdriver; Oct 17th, 2007 at 11:52 AM.
-
Oct 17th, 2007, 07:19 PM
#13
Thread Starter
New Member
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.
-
Oct 18th, 2007, 07:49 AM
#14
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.
 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.
-
Oct 18th, 2007, 07:11 PM
#15
Thread Starter
New Member
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 ?
-
Oct 19th, 2007, 05:30 PM
#16
Re: N00b Question SetTimer KillTimer
 Originally Posted by Harvey.Keitel
Where do you want me to send the money ?
I wish
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|