Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I "schedule" future runs of my program (Continuously)? 1

Status
Not open for further replies.

LSIGuy

MIS
Jun 26, 2002
18
US
Hi,

I wrote a program in VB for Excel and it worked perfect. Now, since I need to compile it, I have transfered it to Microsoft VB 5.0 and my OnTime statements don't work. These statements served to time out my program as it needs to run every 30 minutes. Is there any function that I can use that will achieve this? I would like this program to run on the desktop, so a loop won't work as it steals focus while it is running. Please help!!!!

Thanks,
LSIGuy
 
Have you looked at Scheduled Tasks in Windows? That might be of some use to you. Ah, but looking at your requirement, perhaps not...

I suppose you could set a timer at 180000 milliseconds, but it's hardly cricket, is it?

mmilan
 
There are several alternatives:

One that you can do is to put yourself to sleep for a specified period of time.

First in a Module, make a reference to the Sleep API

Public Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

The Surround your overall program logic with a loop something like the following:

<Execute the Program Logic>
DoEvents
Do While (<ProgramIsRunning>)
Sleep 1800000 ' 30 minutes in milliseconds
<Execute the Program Logic>
DoEvents
Loop

I would also provide some mechanism to terminate the program so that you can reset the ProgramIsRunning condition, however you define that. But note that it will not terminate until the next 30 minute interval, and you will not be able to change that condition while the program is asleep

A second approach is to use the VB Internal Timer, set the Timer Interval to 60000 (1 minute), that's really about as much as you can set it, so for 30 minutes, you will need to control that a little differently. The program will wake up briefly once per minutes to see if its time to go to work.

At the top of the form
Dim WaitMinutes as Integer

In Form_Load - WaitMinutes = 0

The set your timer up something like the following:

Private Sub tmrWaitTime_Timer()

Static WaitMinutes as Integer

if (WaitMinutes < 30) then
WaitMinutes = WaitMinutes + 1
else
WaitMinutes = 0
<Execute Your Logic>
endif

End sub

A third option is to configure the program to run one time, then use the Windows Task Manager to run this program once every 30 minutes.
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
There's also the AT command on Windows NT and 2000. I think for XP it got replaced by the scheduler that mmilan mentioned.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top