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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Firing events - Firing too many times..Please help 1

Status
Not open for further replies.

Scoty

Programmer
Oct 25, 2000
278
0
0
US
I've have serveral overnight jobs that run. For some reason my scheduler will not fire them so I wrote a real quick program to fire them for me. Now when I come in, in the morning, and log into my xp workstation I have several instances of the application (over a 100 per application) running. I'm not real sure why. If you could be so kind please inspect my code and tell me what it is that I am doing wrong

Thanks
Scoty ::)
[Begin Code]
Code:
Public Sub Main()
Top:
'Letters
Do Until Format(Now(), "h:mm:ss ampm") > #6:00:00 PM#
    DoEvents
Loop
Shell "C:\Progra~1\Micros~2\Office\msaccess.exe g:\MyNetWork\scotts.mdb", vbNormalFocus

'More Letters
Do Until Format(Now(), "h:mm:ss ampm") > #7:00:00 PM#
    DoEvents
Loop
Shell "C:\Progra~1\Micros~2\Office\msaccess.exe g:\MyNetWork\sprscott.mdb", vbNormalFocus

'BCM
Do Until Format(Now(), "h:mm:ss ampm") > #8:00:00 PM#
    DoEvents
Loop
Shell "G:\MyNetWork\bcm.exe"

'Loop until midnight then go back to the top
Do Until Format(Now(), "h:mm:ss ampm") > #12:01:00 AM#
    DoEvents
Loop
GoTo Top
End Sub

"Learn from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
Between 8 pm and midnight it will continuously loop back.

1. (minor change)
change ampm to am/pm

2. (This will make the difference)
'Loop until midnight then go back to the top
Do Until Format(Now(), &quot;h:mm:ss am/pm&quot;) <= #12:00:00 PM#
 

Not sure but you may have to Set up a Flag / Boolean telling each do/while when it has executed once. It sounds to me the program is hitting your So/While multiple times between 6:00:00 and 6:00:01 and so forth.

Hope this helps,
J Stephens
 
I think you might also want to take a look at the Sleep API function. You will save quite a few processor cycles by sleeping rather than &quot;DoEvent&quot;ing until you're ready.

Given the time intervals involved, an alternative approach would be to use a system timer (SetTimer API) for the same reasons.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Thanks everone,
I'll give it a try today and let you know what happened tomorrow.

Scoty
::)


&quot;Learn from others' mistakes. You could not live long enough to make them all yourself.&quot;
-- Hyman George Rickover (1900-86),
 
Well I think it ran ok. We had a long July 4th week end and no work got done. So I Can't really tell if the changes worked. I will have to try again tonight. One good thing I didn't have a bunch of applications running when I got in this morning. I used CClint's and JohnStep's idea's.

Sorry will have to let you know tomorrow

Scoty ::)

&quot;Learn from others' mistakes. You could not live long enough to make them all yourself.&quot;
-- Hyman George Rickover (1900-86),
 
Well guys,
Never could get it to run correctly. Talked to one of my computer friends reguarding the scheduler issue. I am running novel cliet and am using the novell scheduler as the scheduler. He said that I had to change the impersination to &quot;User Interactive&quot;. Tried it...and it worked. Just in case anyone wanted to know

Thanks for your help
Scoty ::)


&quot;Learn from others' mistakes. You could not live long enough to make them all yourself.&quot;
-- Hyman George Rickover (1900-86),
 

There may be just a logic problem in the code flow. Seems to work for me though.

> For some reason my scheduler will not fire
Thanks for responding back. and have a star for posting back a solution to this other (original) problem, for others to see...
 
The problem here is with the test for 12:01am. This loop will immediately fall through because the current time actually is > 12:01am (of today, not tomorrow). The only time this will loop is between 12:00am and 12:01am -- all other times are > 12:01am.

In order to make time tests like this work, you need to include the date as well (or at least the day number). That way the test for 12:01am will be for tomorrow at 12:01am and will ignore any times during today. Don't forget when you're setting up your 12:01am test date/time that you need to use tomorrow's date not today's.

Hope that helps.
 
...save quite a few processor cycles by sleeping rather than &quot;DoEvent&quot;ing until you're ready... -CajunCenturion

Yeah, that loop is baking your poor proc. Think of the children! [he cried in SouthPark fashion]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top