0

I have problem in my project ,that is ,i want that time clock is reduced by a specific time suppose in online exam given time is alloted and after a specified time admin will block the exam ,so i want that timer is decremented .
Suppose
aloted time is 01:00(hh:mm)
then time is shown as 00:59(hh:mm) ,00:58 ---like this and after 00:00 exam is closed. So tell me how to do this in vb.net

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Teme64
0

The timer control can't go "backwards". You'll have to "count" the elapsed time "forward"

Private Const MAX_MINUTES As Integer = 60 ' 1 hour, change this value (has to be > 0)
Private CurrentMinute As Integer ' Track minutes
Private CurrentSecond As Integer ' Track seconds

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  '
  Dim hh As Integer ' Hours
  Dim mm As Integer ' Minutes
  ' Reset current time counter
  CurrentMinute = 0
  CurrentSecond = 0
  ' Initialize label
  hh = MAX_MINUTES \ 60
  mm = MAX_MINUTES - (hh * 60)
  ' Update label
  Label1.Text = hh.ToString.PadLeft(2, CChar("0")) & ":" & mm.ToString.PadLeft(2, CChar("0"))
  ' Set timer to tick once a second
  Timer1.Interval = 1000 ' 1000 ms
  ' Start the timer
  Timer1.Start()

End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  '
  Dim RemainingMinutes As Integer ' Remaining time
  Dim hh As Integer ' Hours
  Dim mm As Integer ' Minutes
  ' A one second elapsed, add seconds
  CurrentSecond += 1
  ' One minute?
  If CurrentSecond = 60 Then
    ' Reset seconds
    CurrentSecond = 0
    ' A one minute elapsed, add minute
    CurrentMinute += 1
    ' Calculate remaining time
    RemainingMinutes = MAX_MINUTES - CurrentMinute
    ' Get hrs and mins
    hh = RemainingMinutes \ 60
    mm = RemainingMinutes - (hh * 60)
    ' Update label
    Label1.Text = hh.ToString.PadLeft(2, CChar("0")) & ":" & mm.ToString.PadLeft(2, CChar("0"))
    ' All the time elapsed?
    If RemainingMinutes = 0 Then
      ' Stop the timer
      Timer1.Stop()
      ' Time's up!
      Label1.Text = Label1.Text & " Time's up!"
    End If
  End If

End Sub

Just subtract the elapsed time from the given exam time and you have a "backward" timer.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.