Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Visual Basic daily/etc. timer help.

    I Googled for help on this and only came across the built-in timer, but from what I found it only goes up to about 30 seconds (unless those sources were incorrect). Any help on accomplishing a task based on user input of hourly/daily/etc. (assuming the program will be run at all times.)

    The program I have made is an automatic background randomizer, but I feel that's not really important information since I just need to know how to do something, say, once an hour or day or so on.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Perhaps a windows service is more what you're looking for?
    A service runs in the background, and with vb.net, can basically have a Timer that does something every X minutes or whatever.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by nikkiH View Post
    Perhaps a windows service is more what you're looking for?
    A service runs in the background, and with vb.net, can basically have a Timer that does something every X minutes or whatever.
    Sounds probably what I need. How would I accomplish using this?

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Intro to window service, I believe it's in 2003 but there seems to be a link to 05 as well:
    http://www.developerfusion.co.uk/show/3441/

  • #5
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Brandoe85 View Post
    Intro to window service, I believe it's in 2003 but there seems to be a link to 05 as well:
    http://www.developerfusion.co.uk/show/3441/
    From that I have found some useful things regarding it, but it appears that I don't have the Windows Service template. It says only Standard Edition doesn't allow it (I have Express), so what's the deal?

    Edit: With further investigation, I now understand that this version doesn't come with it either, however still lets you use the functionality.
    Last edited by Scriptdaemon; 05-17-2007 at 04:29 PM.

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    You can store a date/time in the future when you want to change the background, then you can use the timer to check the current date and time against when it is supposed to change. When they match, you do your background changing thing.
    OracleGuy

  • #7
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy View Post
    You can store a date/time in the future when you want to change the background, then you can use the timer to check the current date and time against when it is supposed to change. When they match, you do your background changing thing.
    This isn't regarding a Windows Service is it? Because it's proving to be more difficult than I find necessary. (Plus I don't really want to have to install it, which seems to be mandatory if a Windows Service is used.)

    Could you start me off just a bit on how to use a date/time in VB and how to use, say, a day ahead of time then have the timer compare itself to that time?

  • #8
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by Scriptdaemon View Post
    This isn't regarding a Windows Service is it? Because it's proving to be more difficult than I find necessary. (Plus I don't really want to have to install it, which seems to be mandatory if a Windows Service is used.)

    Could you start me off just a bit on how to use a date/time in VB and how to use, say, a day ahead of time then have the timer compare itself to that time?
    What I was talking about didn't require a service. As for code, maybe a little later today. It's been a few months since I've done any VB.NET.
    OracleGuy

  • #9
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy View Post
    What I was talking about didn't require a service. As for code, maybe a little later today. It's been a few months since I've done any VB.NET.
    Alright, thanks. I appreciate it. I'll do a little Googling about this as well.

  • #10
    New Coder
    Join Date
    Dec 2006
    Posts
    95
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Alright, I found a way to do it where I would use:

    Code:
    Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    
    Private Sub timerProc(ByVal hwnd As Long, ByVal lMsg As Long, ByVal lTimerID As Long, ByVal lTimer As Long)
            changeDesktopBackground()
    End Sub
    But it says to use something like startTimer = SetTimer(0, 0, 300, AddressOf timerProc) to start it, but I always get an error saying "'AddressOf' expression cannot be converted to 'Long' because 'Long' is not a delegate type."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •