Solved

I need to use a timer in my web app, are there any timer controls available or is there an easy way round this problem?

Posted on 2004-09-29
10
185 Views
Last Modified: 2010-04-23
I need to time an exam.

At the start of the exam I must give the candidates 10 minutes to answer 10 questions.

The timer must be visible to the user.

If the timer ticks down to zero, I must be able to program something to happen by this event.

Your help would be much appreciated.

Regards

PG
0
Comment
Question by:pgilfeather
  • 5
  • 3
  • 2
10 Comments
 
LVL 14

Expert Comment

by:dfu23
ID: 12180594
You could start with something like

<script type="text/javascript">
    var i = 0;
    window.onload = function() {
        window.setInterval("endExam()", 1000);
    };
    function endExam() {
        i++;
        if (i == 600) { // 600 seconds is 10 minutes
            document.location.href = "timesUp.htm";
        }
    }
</script>
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12180666
 Public m_Timer As System.Timers.Timer

  AddHandler m_Timer.Elapsed, AddressOf TimerTick

  Private Sub TimerTick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

  End Sub

Bob
0
 

Author Comment

by:pgilfeather
ID: 12180677
How would I put this in my .aspx page.

Do I treat the script part as I would a piece of VB.NET?

and what about the display?

Im not really very sure when it comes to javascript but I know for this kind of feature I really do need to get into a bit of it.

Could you explain a bit further on the code you have supplied.

Thanks very much, I really do appreciate it.

PG
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 12180705
Do you need a display?


In the code-behind page:

Public m_Timer As System.Timers.Timer = New System.Timers.Timer

 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here

    AddHandler m_Timer.Elapsed, AddressOf TimerTick

  End Sub

  Private Sub TimerTick(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)

  End Sub

Bob
0
 

Author Comment

by:pgilfeather
ID: 12180711
TheLearnedOne,
could you explain further please?

I am a beginner at this.

cheers

PG
0
 
LVL 14

Expert Comment

by:dfu23
ID: 12180730
Ok, basically Javascript is sent with the HTML that is sent to your clients machine ... it is then parsed and run on their machine ...

You should place the <script> tags in between the <head> tags of your document. As far as displaying the time ... how do you want to do it? something that displays text like "10:00" and then ticks down every second ... "9:59", "9:58" etc ... ? or something different?

And then, what needs to happen when it reaches "0:00"? Submit the exam even if they are not done? Or just navigate to another page?
0
 

Author Comment

by:pgilfeather
ID: 12180753
You have explained what I want to do exactly.

How can I accomplish this?

PG
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12180759
What do you need explained?

(1) Define a timer variable at the top of the module, above the Page_Load event.

(2) Add an event handler to the variable in the Page_Load event

(3) Set the interval (milliseconds) in the Page_Load event:  m_Timer.Interval = 1000 * 60 * 10  ' 10 minutes.

(3) Add the Timer_Tick event sink below the Page_Load event.  The event handler needs the signature as shown.

Open the web page, view the code behind page, and paste this code into the places indicated.

Bob
0
 

Author Comment

by:pgilfeather
ID: 12180809
"9:59", "9:58" etc ... this will do me
0
 

Author Comment

by:pgilfeather
ID: 12180902
TheLearnedOne,

yes, I need a display.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Put window Form inside tab page 10 33
Advice in Xamarin 21 78
VB.Net - Windows UserName index and length error 4 29
Close form "before" open 3 39
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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…

813 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

10 Experts available now in Live!

Get 1:1 Help Now