Click here to Skip to main content
Email Password   helpLost your password?

Introduction

ASP is commonly used on Microsoft Servers and other compatible platforms to build dynamic web pages and also to retrieve data from databases. ASP supports various scripting languages like VBScript, JScript, etc. These scripting languages provide the business logic to the web pages while ASP is used to provide dynamic content to the webpage.

Briefing About The Problem

I came across a problem when I was building an Online Examination System for my Institute. The problem was to restrict the student's time, i.e., the student must answer all the questions in the exam in a specific time. For that, I had to attach a timer to the web page. I made use of VBScript inside the ASP page. I assume here that the reader is conversant in VBScript, if not, it is not a problem, just mail me at email@gauravsonline.com if you have any queries related to the subject. I would definitely reply.

Example

Now comes the explanation of how it's done. I am trying to simulate a "count down clock". This is explained as follows with the help of the following ASP example:

'************************************************************* 

'This program makes use of a recursive procedure HandleTime.

'The important aspects of the code are "Status" and "setTimeOut". 

'Status is an attribute of the Window object in VBScript and is used to 

'change the status message of the active window. 

'setTimeOut is a VBScript function that tells after how much time the timer 

'would stop and accordingly it calls a function passed into it to take some 

'action when the time is up.

'This procedure calls its self after every 1 sec (I have taken 1sec = 950ms

' here) and accordingly the variables hr, min and sec are decremented. 

'************************************************************* 

Sub HandleTime 
    if hr=0 and min=0 and sec=0 then 
        EndTime 
        '**When hr, min and sec are all 0, this means that the time is up 

        '**and EndTime procedure is 'called. 

    elseif min>=0 and sec>0 then 
        sec=sec-1 
        status=hr & ":" & min & ":" & sec 
        '**Whenever the second changes the Status of the window has to 

        'be changed. 

        intTimerID=setTimeOut("HandleTime",950, "VBScript") 
        '**setTimeOut function returns a unique timer id that is used to 

        'keep track of the time. 

        '**When the time is up the timer id is destroyed automatically. 

    elseif min>0 and sec=0 then 
        min=min-1 
        sec=59 
        status=hr & ":" & min & ":" & sec 
        intTimerID=setTimeOut("HandleTime",950, "VBScript") 
    elseif hr>=0 and min=0 then 
        hr=hr-1 
        min=59 
        sec=59 
        status=hr & ":" & min & ":" & sec 
        intTimerID=setTimeOut("HandleTime",950, "VBScript") 
    end if 
End Sub 

Sub EndTime 
    clearTimeOut intTimerID 
    '**clearTimeOut is a built in procedure of VBScript which is used to 

    '**clear and destroy the timer id explicitly 

    status = "Your Time Ended" 
    '**When the time ends the status bar displays this message. 

    msgbox "Time Up" 
End Sub

How To Use The Source Code

To run the ASP code, you must have an ASP enabled web server such as Microsoft Personal Web Server or IIS installed on your system and select the publishing directory. This code could also be executed from a simple .htm file without requiring PWS or IIS installed.

When you run the program, you would see that the clock starts from 0:2:0 and ends at 00:00:00. You can use the variables hr, min and sec in the program to change the time. Moreover, you can also connect a form from which you can specify inputs to these variables and hence you can have your own time constraints.

Warning

This code could only be executed inside browsers with VBScript built in. For example: IE 4.0 or higher.

Screenshots of the Program

Here, you can see that the time starts at 0:2:0. The time ends after two minutes and then the message is displayed like this:

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
Questiondemonstrate using vb.net
swatigodkhindi
22:54 14 Apr '09  
how Administrator monitors client?
how administrator will filter the sites used by client?
AnswerRe: demonstrate using vb.net
Gaurav Saini
6:00 15 Apr '09  
I am still not able to understand what are you loooking for.
Can you please elaborate your prob scenario.
Generalsending data automatically when the time runs out
mhelo
23:48 1 Apr '08  
hi good afternoon, can i ask you something. how can i send a data in a database automatically when the time is stop.Smile please help me
QuestionTimer Control
bhappi
22:22 23 Jan '08  
When click on refresh button time start from begining...

but i want that time start from continuous time...

please help me out...
Questiontimer coding
bhappi
22:18 23 Jan '08  
when we click on refresh button, timer run from stating time....

but i want that when i click refresh, timer go from continuous time....

what is the solution....?
GeneralActiveX that displays images using ASP
awni
9:32 12 Jan '04  
Hi
I made an ActiveX(with VC++ 6.0) control that displays images, it works fine outside of a browser,
I tried it with a VB and a VC program, no problems. I was able to use the OBJECT tag in plain HTML
and got it to work in IE locally.

Problems :
1- Failed to get it to work over a LAN
2- How can I get it to work over a LAN, and over the Internet using ASP ?

thanks

awni

GeneralFails to meet expectations
PFunky
13:49 15 Sep '03  
This article fails to address the other issues of dealing with client-side timers.

- How do you restrict a student from reloading the page/frame?
- No security measures are taken if I bring up "Internet Options" which causes the timer to pause, giving the student as much time as they want.

Fails to meet the requirements.
GeneralRe: Fails to meet expectations
Gaurav Saini
5:01 16 Sep '03  
yes u can do it with either VBScript or JavaScript:
1> disable the menus and the toolbars for ur client
2> create a database that would keep track of the user appearing for the test
3> allow only 2 tries to resume test from backend itself...

u have to be serious for this issue and this can be implemented through programming only...
my article gives only the code of the timer rest the back work ...
hope that solves the problem
regards
gaurav
Generalhow can i run it in the server ??
yanivbd
3:09 5 Sep '03  
hello,

i want to run this script on the server side...

how can i do it ??
GeneralEh
Victor Vogelpoel
6:41 23 Nov '02  
Ehrm, this article has nothing to do with ASP. It's all client vbscript page which happens to be in an .ASP page.
And this client vbscript can only executed by Internet Explorer...

Victor
GeneralRe: Eh
gauravsaini
3:21 25 Nov '02  
don't be irritated,
this article is basically shown here for reference to all those who are not able to use a timer when building projects
any ways
thank for ur precious comments
GeneralRe: Eh
Victor Vogelpoel
5:46 25 Nov '02  
gauravsaini wrote: don't be irritated
Well, I think you've made some bad choices, which makes this article a poor one. Lately, CodeProject is being swamped by code-only and lesser quality articles and yours unfortunately is one of them in its current form.

As I said, the article has nothing to do with ASP and you classified it as thus, which is somewhat misleading. Your code will run just as well in an plain HTML file, because it's all executed client side and not server side, as I presume you think it is. IIS or ASP are not needed at all in this project.

Futher more, only Internet Explorer is able to execute your code because only Internet Explorer can execute vbscript client side. If you would have implemented your design in javascript, more browsers (Netscape, Mozilla, Opera...) can execute the code as well, which makes this article much more useful for other people. Or did you intend it to be IE exclusive and forgot to mention this in the article?

Victor
GeneralRe: Eh
Steve McLenithan
6:43 25 Nov '02  
i agree

********************
* SteveMcLenithan
* steve@steve-mac.com * http://steve-mac.com ********************
GeneralRe: Eh
gauravsaini
19:25 26 Nov '02  
I have clearly mentioned that i used VBSCRIPT as part of the ASP page... i know what u r trying to say...thanks for the additional knowledge...but that is not required...

VBSCRIPT is just a scripting langauage and in know way does it matter that u r using IE ot NE... obviously the programmer should know what platform he is working on before going for coding... soft. eng. says a lot about it

with regards
gaurav


GeneralRe: Eh
Victor Vogelpoel
22:13 26 Nov '02  
I think you are still missing the point.

gauravsaini wrote: I have clearly mentioned that i used VBSCRIPT as part of the ASP page... True, lets do a test. If you load this page in IE and view the source of the page using View | Source. If you can see the VBScript in the source, then it is executed client side. ASP is not parsing this script server side!

gauravsaini wrote: VBSCRIPT is just a scripting langauage and in know way does it matter that u r using IE ot NE
Test number two: run your page in Netscape, Mozilla or Opera. You'll find that absolutely nothing happens but showing the page. NO timer is running. These browsers cannot handle a scripting language "VBscript" and simply ignore the script that you wrote in the page.

Victor
GeneralRe: Eh
Anonymous
14:56 24 Jun '03  
No sh*t it doesn't run on Netscape but I got 5,000 clients on IE and it works sweet.

GeneralRe: Eh
Anonymous
20:05 24 Jun '03  
I bet ye it even runs on 1.000.000 clients and it still works sweet... but it still has nothing to do with ASP.


Last Updated 13 Sep 2003 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010