Results 1 to 12 of 12

Thread: Calling a function at a certain time.... [Solved]

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved Calling a function at a certain time.... [Solved]

    Is there a way to do this in VB? I would like to have an app up and running and at a certain time everyday perform a task?

    Thanks for any help.
    Last edited by Besoup; Feb 28th, 2005 at 03:50 PM.

  2. #2
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calling a function at a certain time....

    well, this is how id do it.
    VB Code:
    1. if now = (time/date/whatever) then
    2. call jesus

    is that what you wanted?

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Calling a function at a certain time....

    Quote Originally Posted by |2eM!x
    well, this is how id do it.
    VB Code:
    1. if now = (time/date/whatever) then
    2. call jesus

    is that what you wanted?

    In theory yes... just wondering if there was a type of clock/control that once it hit a certain time in the day that it might be able to call a function. With the code you posted I would have to have a nonstop loop checking if now is the right time and would rather not do that...

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

    Re: Calling a function at a certain time....

    Quote Originally Posted by Besoup
    In theory yes... just wondering if there was a type of clock/control that once it hit a certain time in the day that it might be able to call a function. With the code you posted I would have to have a nonstop loop checking if now is the right time and would rather not do that...
    Thats the only way you are going to do it using VB. If you are using SQL Server or Oracle, you might be able to write a Stored Procedure to do whatever function you need done and have it kick off at a certain time.

    If you are using Access, then I think you would have to develop some type of Server side Service that ran at the OS level.
    Last edited by Hack; Feb 28th, 2005 at 02:57 PM.

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Calling a function at a certain time....

    Quote Originally Posted by Besoup
    Is there a way to do this in VB? I would like to have an app up and running and at a certain time everyday perform a task?

    Thanks for any help.
    Why does your app have to be up and running all day long just for this?

    Windows has a schedule task feature for you to select a date/time for a .EXE to be run. The .EXE should really have no form - just a SUB MAIN area of code - and that executes and when done, exits.

    Kind of like a service.

    We have lots of these little .EXE jobs run from SQL Agent - and a couple from SCHEDULE TASKS...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Calling a function at a certain time....

    Quote Originally Posted by szlamany
    Why does your app have to be up and running all day long just for this?

    Windows has a schedule task feature for you to select a date/time for a .EXE to be run. The .EXE should really have no form - just a SUB MAIN area of code - and that executes and when done, exits.

    Kind of like a service.

    We have lots of these little .EXE jobs run from SQL Agent - and a couple from SCHEDULE TASKS...
    Never thought of writing something for Scheduled tasks, probalby will be the best way to do it.... to answer your question of being up all day, the main app I am working on is going to be up all day just running processes of a regular timer.

  7. #7
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Calling a function at a certain time....

    or run a timer,you could run something every 60 seconds or something that way also

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Calling a function at a certain time....

    Quote Originally Posted by szlamany
    Why does your app have to be up and running all day long just for this?

    Windows has a schedule task feature for you to select a date/time for a .EXE to be run. The .EXE should really have no form - just a SUB MAIN area of code - and that executes and when done, exits.

    Kind of like a service.

    We have lots of these little .EXE jobs run from SQL Agent - and a couple from SCHEDULE TASKS...
    BTW I have never just made a .exe without form in VB. How would I declare a main sub in a VB Class?

    tried :
    VB Code:
    1. Sub Main()
    2. 'put code in
    3. End Sub

    code didn't run off the .exe... any ideas?

  9. #9
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Calling a function at a certain time....

    Quote Originally Posted by Besoup
    BTW I have never just made a .exe without form in VB. How would I declare a main sub in a VB Class?

    tried :
    VB Code:
    1. Sub Main()
    2. 'put code in
    3. End Sub

    code didn't run off the .exe... any ideas?
    Menu - PROJECT>PROPERTIES>General Tab...

    Startup Object -set to Sub Main - should do it.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Calling a function at a certain time....

    Tried that and am now getting:

    "Must have startup form or Sub Main()"

    I have:
    VB Code:
    1. Sub Main()
    2. MsgBox "OMG"
    3. End Sub

    Am I not putting the code in the right place?

  11. #11
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Calling a function at a certain time....

    I just started a brand new project.

    Added a MODULE.

    Put into that MODULE a SUB called MAIN

    Code:
    Sub main()
    
    MsgBox "hello"
    
    End Sub
    Set the STARTUP OBJECT to "SUB MAIN".

    Ran it and got the message box!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Calling a function at a certain time....

    Quote Originally Posted by szlamany
    I just started a brand new project.

    Added a MODULE.

    Put into that MODULE a SUB called MAIN

    Code:
    Sub main()
    
    MsgBox "hello"
    
    End Sub
    Set the STARTUP OBJECT to "SUB MAIN".

    Ran it and got the message box!
    Got it thanks... I guess it would help not to have the main sub in the form code :P

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