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
706 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
  • 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now