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
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 25

Assisted Solution

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

Accepted Solution

schalcraft earned 200 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...
Independent Software Vendors: 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!


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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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