|
-
Feb 28th, 2005, 02:11 PM
#1
Thread Starter
Frenzied Member
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.
-
Feb 28th, 2005, 02:19 PM
#2
Re: Calling a function at a certain time....
well, this is how id do it.
VB Code:
if now = (time/date/whatever) then
call jesus
is that what you wanted?
-
Feb 28th, 2005, 02:43 PM
#3
Thread Starter
Frenzied Member
Re: Calling a function at a certain time....
 Originally Posted by |2eM!x
well, this is how id do it.
VB Code:
if now = (time/date/whatever) then
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...
-
Feb 28th, 2005, 02:53 PM
#4
Re: Calling a function at a certain time....
 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.
-
Feb 28th, 2005, 02:56 PM
#5
Re: Calling a function at a certain time....
 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...
-
Feb 28th, 2005, 03:03 PM
#6
Thread Starter
Frenzied Member
Re: Calling a function at a certain time....
 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.
-
Feb 28th, 2005, 03:03 PM
#7
Re: Calling a function at a certain time....
or run a timer,you could run something every 60 seconds or something that way also
-
Feb 28th, 2005, 03:21 PM
#8
Thread Starter
Frenzied Member
Re: Calling a function at a certain time....
 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:
Sub Main()
'put code in
End Sub
code didn't run off the .exe... any ideas?
-
Feb 28th, 2005, 03:24 PM
#9
Re: Calling a function at a certain time....
 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:
Sub Main()
'put code in
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.
-
Feb 28th, 2005, 03:34 PM
#10
Thread Starter
Frenzied Member
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:
Sub Main()
MsgBox "OMG"
End Sub
Am I not putting the code in the right place?
-
Feb 28th, 2005, 03:38 PM
#11
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!
-
Feb 28th, 2005, 03:49 PM
#12
Thread Starter
Frenzied Member
Re: Calling a function at a certain time....
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|