Solved

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
6
727 Views
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!"  
	   
	   
       Else    
	   PeriodState = ""
	   
	   End If 
	   
	
 
End Function 
 
 
 
%>
 
<% Function writePeriod
   
      response.write PeriodState()	
 
End Function %>
 
<%Call writePeriod %>

Open in new window

0
Comment
Question by:tony_wheeler
[X]
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
6 Comments
 
LVL 25

Assisted Solution

by:SStory
SStory earned 50 total points
ID: 21821686
What about Javascript and DHTML?
0
 
LVL 2

Accepted Solution

by:
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.
0
 

Author Comment

by:tony_wheeler
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...
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:tony_wheeler
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!
0
 

Author Closing Comment

by:tony_wheeler
ID: 31468743
Thanks Folks
0
 
LVL 25

Expert Comment

by:SStory
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:
http://www.w3schools.com/JS/default.asp

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:
http://www.w3schools.com/dhtml/default.asp

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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

630 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