Solved

Execute a Sub every hour

Posted on 2013-01-18
4
294 Views
Last Modified: 2013-01-19
Hello Experts,

I need to execute a sub routine every hour, and I have the following code to so, but it's not happening...

	If (Session("getRates") = "") Or (CDate(Session("getRatesTime")) > Now()) Then
		
		'Call UpdateRates
		
		Session("getRates") = False
	
		'Renew Rates every hour
		Session("getRatesTime") = DateAdd("s", 3, Now())	'DateAdd Intervals: s=secs; n=minutes; h=hrs

	End If

Response.Write("ts = " & Session("getRatesTime") & "<br>")
Response.Write("now = " & Now())

Open in new window


It executes once, whern getRates = "", then the first Writeline doesnt change.

Any ideas?

I have it set to 3s for this test...

Thank you.
0
Comment
Question by:APD_Toronto
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 38795325
Try switching it around, also you don't need CDate:
	If (Session("getRates") = "") Or (Session("getRatesTime") < Now()) Then

Open in new window

0
 
LVL 32

Expert Comment

by:Robberbaron (robr)
ID: 38796163
while previos comment is probably the correct test, what method did you have in mind for getting the script to wait the 3600 seconds.
What causes the script to reload ?  Page.Redirect ?

your asp page is going to be running continuously.... is that what you expect ?

executing every hour, i think it would be more efficient to have the script run using windows scheduler and update a background file with the data but that may not suit your users .
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38796167
I do agree 100% that this should not be  run as asp page, but by a scheduler
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 38796177
I assumed it would not be running continuously but rather check on each use of a page (or even any page on a site via a global include file) whether a set of information needed refreshing.

EDIT: For that of course you may need to use Application instead of Session. But if you just need this within each individual user's session then it should do the job.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question