Go Premium for a chance to win a PS4. Enter to Win


How to to periodically call a VBscript function to update a value, similar to that of a live clock showing live update of seconds

Posted on 2008-06-19
Medium Priority
Last Modified: 2010-04-21
I'm developing an intranet for a school. I've written a basic ASP/VBScript function to return a value displaying what the current period is, and I need this to dynamically update live in the page, without a page refresh (much the same way as you might see the seconds tick by when deisplaying a clock in a page).

The code has actually been broken down into two functions, the second being simply holding a response.write, which helped when I was experimenting with different solutions. I can change this back to a simple <%=Periodstate()%> but thought I'd leave it as is for now, in case there is a way of calling just that function? I'm not exactly a noob, but noither am i a nerd.

I think what I'm looking for is something like a javascript "timeout" or "interval"
 Function PeriodState()
	Dim TWDate
	TWDate= WeekDay(Now())
	Dim TWTime
	TWTime= TimeValue(Now())
If TWDate =1  Then DayState="Sunday"_
Else IF TWDate  = 7 Then DayState="Saturday"_
Else DayState="Weekday"_
End IF 
If (DayState = "Weekday") And (TWTime > "08:39") And (TWTime < "08:54") Then  
       PeriodState = "Chapel"  
           ElseIf (DayState = "Weekday") And (TWTime > "08:54") And (TWTime < "09:54") Then  
       PeriodState = "Lesson 1"  
           ElseIf (DayState = "Weekday") And (TWTime > "09:55") And (TWTime < "10:49") Then  
       PeriodState = "Lesson 2"  
           ElseIf (DayState = "Weekday") And (TWTime > "10:50") And (TWTime < "11:19") Then  
       PeriodState = "The Half"  
           ElseIf (DayState = "Weekday") And (TWTime > "11:20") And (TWTime < "12:19") Then  
       PeriodState = "Lesson 3"  
           ElseIf (DayState = "Weekday") And (TWTime > "12:20") And (TWTime < "13:14") Then  
       PeriodState = "Lesson 4"  
           ElseIf (DayState = "Weekday") And (TWTime > "13:15") And (TWTime < "13:59") Then  
       PeriodState = "Lunch"  
           ElseIf (DayState = "Weekday") And (TWTime > "14:00") And (TWTime < "14:19") Then  
       PeriodState = "Tutor Period"  
           ElseIf (DayState = "Weekday") And (TWTime > "14:20") And (TWTime < "15:19") Then  
       PeriodState = "Lesson 5"  
           ElseIf (DayState = "Weekday") And (TWTime > "15:20") And (TWTime < "16:14") Then  
       PeriodState = "Lesson 6"  
           ElseIf (DayState = "Weekday") And (TWTime > "16:15") And (TWTime < "17:29") Then  
       PeriodState = "After Four"  
           ElseIf (DayState = "Weekday") And (TWTime > "17:30") And (TWTime < "18:29") Then  
       PeriodState = "First Prep"  
           ElseIf (DayState = "Weekday") And (TWTime > "18:30") And (TWTime < "19:29") Then  
       PeriodState = ""  
           ElseIf (DayState = "Weekday") And (TWDate = "3") OR (TWDate = "5") AND (TWTime > "19:30") And (TWTime < "20:59") Then  
       PeriodState = "Second Prep (Late)"  
           ElseIf (DayState = "Weekday") And (TWDate = "2") OR (TWDate = "4") OR (TWDate = "6") AND (TWTime > "19:30") And (TWTime < "20:29") Then  
       PeriodState = "Second Prep"  
           ElseIf (DayState = "Weekday") And (TWDate = "3") OR (TWDate = "5") AND (TWTime > "21:00") And (TWTime < "21:29") Then  
       PeriodState = ""  
           ElseIf (DayState = "Weekday") And (TWDate = "2") OR (TWDate = "4") OR (TWDate = "6") AND (TWTime > "20:30") And (TWTime < "21:29") Then  
       PeriodState = ""  
	  	   ElseIf (DayState = "Weekday") And (TWTime > "21:30") And (TWTime < "22:30") Then  
       PeriodState = "Quiet Time"  
           ElseIf (DayState = "Saturday") And (TWTime > "08:29") And (TWTime < "09:14") Then  
       PeriodState = "Lesson 1"  
           ElseIf (DayState = "Saturday") And (TWTime > "09:15") And (TWTime < "09:59") Then  
       PeriodState = "Lesson 2"  
           ElseIf (DayState = "Saturday") And (TWTime > "10:00") And (TWTime < "10:44") Then  
       PeriodState = "Lesson 3"  
           ElseIf (DayState = "Saturday") And (TWTime > "10:45") And (TWTime < "11:29") Then  
       PeriodState = "Lesson 4"  
           ElseIf (DayState = "Saturday") And (TWTime > "11:30") And (TWTime < "11:54") Then  
       PeriodState = "The Half"  
           ElseIf (DayState = "Saturday") And (TWTime > "11:55") And (TWTime < "12:45") Then  
       PeriodState = "Study Period"  
           ElseIf (DayState = "Saturday") And (TWTime > "12:45") Then  
       PeriodState = "Enjoy Your Weekend!"  
	   ElseIf (DayState = "Sunday") Then  
       PeriodState = "Enjoy Your Weekend!"  
	   PeriodState = ""
	   End If 
End Function 
<% Function writePeriod
      response.write PeriodState()	
End Function %>
<%Call writePeriod %>

Open in new window

Question by:tony_wheeler
  • 3
  • 2
LVL 25

Assisted Solution

SStory earned 150 total points
ID: 21821686
What about Javascript and DHTML?

Accepted Solution

schalcraft earned 600 total points
ID: 21821755
You have to remember that the asp code is run at the web server the generate the html ouput, but it only does so when a client requests the web page. Once the web page has been generated and sent back to the client, the web server can no longer push out updates to the clients.
You will need a client side script (ie javascript) with a timer to either update the output field, or to request the server to re-generate the web page.
If you need to have flexibility to alter the javasript, the you can use the asp code to write out different javacode based on the day the page is loaded.

Author Comment

ID: 21821771
>Thanks SStory

Well, this is a very small additional component to an asp template within our new Content Management System, which i originally thought would be quick and dirty! I don''t know enough about Javascript or DHTML to know where to start... at least with ASP I got half-way there!

I just thought I'd stick with ASP and try to find something that maybe went:
1: Write function value > 2: wait five seconds > 3: delete function value > 4: Loop back to 1

But if it's not possible, I'll guess I'll start to look at alternatives...
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 21821807
Thanks for reminding me Schalcraft... good point! I guess that's why all the solutions i've come across only seem to be in Javascript! Okay, I'll take a look at puting something like that together!

Author Closing Comment

ID: 31468743
Thanks Folks
LVL 25

Expert Comment

ID: 21822002
Well javascript has the feel of C.  There are plenty of samples. I don't know it perfectly either. I just look for samples and online manuals:

I haven't done much DHTML, but what I did was neat.  Basically you change the content within a tag or ID dynamically on the client side.  So javascript would do what your server side code is doing.  It is similar.  It is case sensitive

if (DayState == "Weekday") && (TWTime > "08:39") && (TWTime < "08:54") {
  //do some stuff

Here's tutorials on DHTML:

Also, there is AJAX (async. java). I haven't used it but basically it seems that the page calls the server through java script and refreshes only a portion of the page without having to reload the entire page.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

886 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