View Full Version : VB.NET - how to put in an automatic timer?
muhammed_1428
31-03-08, 08:47 PM
Salaam
Basically I just made a 20 question multiple choice test - and now wish to add a time limit for the user to complete the test of say, ten minutes, in which when the ten mins finishes the application closes automatically - how do I do this?
Also, how would I be able to display the time left for the user to see?
JZK for any help and/or advice!
ammarcool
01-04-08, 09:17 AM
Salaam
Basically I just made a 20 question multiple choice test - and now wish to add a time limit for the user to complete the test of say, ten minutes, in which when the ten mins finishes the application closes automatically - how do I do this?
Also, how would I be able to display the time left for the user to see?
JZK for any help and/or advice!
:wswrwb:
yes brother you can do accomplish your goal as for your expectation inshallah! :) just put a time control and set the interval as 1000 ms. you have to calculate hours + minutes + seconds separately. when the timer controls ticks equals the time specified by your set time then you have to write the codes to exit from the application.
you have to use DateAdd().ToString("HH:mm:ss") like functions :rubeyes: to countdown your time. :)
brother when the application get closed automatically what will happen to the questoins that he has finshed answering? just a suggestion, dont exit from the application. just disable those questions or the buttons and display the MARKS.
brother just try it else just let me know or PM me.
:jkk:
ammarcool
02-04-08, 11:19 AM
brother this is the code for your question:
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim MyHours As Integer = 0
Dim MyMinutes As Integer = 0
Dim MySeconds As Integer = 10
dtFullDateFormat = New DateTime(1, 1, 1, MyHours, MyMinutes, MySeconds)
intDuration = MyHours * 3600 + MyMinutes * 60 + MySeconds
Label1.Text = dtFullDateFormat.ToString("HH:mm:ss")
Timer1.Interval = 1000
blnStart = True
Timer1.Start()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Static Ticks As Integer = 0
Try
If blnStart Then
Ticks = 0
blnStart = False
End If
If Ticks = intDuration Then
Timer1.Enabled = False
'MessageBox.Show("Dude, Time is up! be ready to get your Results")
Application.Exit()
Else
Ticks += 1
Label1.Text = DateAdd(DateInterval.Second, -Ticks, dtFullDateFormat).ToString("HH:mm:ss")
Label1.Refresh()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Hobbitbeats
15-04-08, 12:26 AM
Hi,
This is exactly what i am stuck on!
After using your code ammarcool (which is greatley appriciated) VB would not compile since it cound't declare some expression like:
dtFullDateFormat
intDuration
blnStart
Why is this? I am very confused, please help :):)
H
vBulletin® v3.7.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.