Results 1 to 16 of 16

Thread: N00b Question SetTimer KillTimer

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    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

  2. #2

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    Re: N00b Question SetTimer KillTimer

    vb Code:
    1. Private Sub Timer1_Timer()
    2. If Now > DateValue(txtDate.Text) + TimeValue(txtTime.Text) Then
    3. ' Do the function i need
    4. txtDate.Text = Format$(Date + 1, "dd/mm/yy")
    5. txtTime.Text = "23:00:00"
    6. End If
    7. 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.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: N00b Question SetTimer KillTimer

    The VB Timer control is not known for its accuracy so I would stick with your API solution.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    Re: N00b Question SetTimer KillTimer

    Hmmm...

    I Don't have an api solution, only a resounding question..

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: N00b Question SetTimer KillTimer

    Quote 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.
    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?

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    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.

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: N00b Question SetTimer KillTimer

    See if this helps.

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    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.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    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

  11. #11

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    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 ?

  12. #12
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    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.

  13. #13

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    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.

  14. #14
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: N00b Question SetTimer KillTimer

    vb Code:
    1. Option Explicit
    2.  
    3. 'Form level code.
    4.  
    5. Private Sub Form_Load()
    6.    Call StartTimer
    7. End Sub
    8.  
    9. Private Sub Form_Unload(Cancel As Integer)
    10.    Call KillTimer(0&, intTimerID)
    11. End Sub
    vb Code:
    1. Option Explicit
    2.  
    3. 'Module level code.
    4.  
    5. 'Timer APIs. Allow events of @ 25 days.
    6. 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
    7. Public Declare Function KillTimer Lib "user32.dll" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
    8.  
    9. 'Timer identifier.
    10. Public intTimerID  As Long
    11.  
    12. Private Const TIMEOUT As Long = 5000 'Test - 5 seconds.
    13. 'For 4 hours this would be: 4 x 60 x 60 x 1000 = 14400000
    14. 'Can be up to 2147483647 (a  Long)
    15.  
    16. Public Sub StartTimer()
    17. 'Create the timer.
    18.    intTimerID = SetTimer(0&, 0&, TIMEOUT, AddressOf MyTimer)
    19. End Sub
    20.  
    21. Private Sub MyTimer(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
    22. 'This callback sub MUST be in a module.
    23.  
    24. 'Do your stuff
    25.    MsgBox "Hello World"
    26.  
    27. 'Destroy the timer - IF you only want a SINGLE event.
    28. '----------------------------------------------------
    29. 'You don't HAVE to do this right away, but you MUST
    30. 'do it before you unload your application.
    31.    Call KillTimer(0&, intTimerID)
    32. 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.

  15. #15

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    10

    Talking 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 ?

  16. #16
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: N00b Question SetTimer KillTimer

    Quote 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
  •  



Click Here to Expand Forum to Full Width