View Single Post
Old 08-06-2014, 08:09 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024

RemainingTime is the remaining time in seconds.
It is a Long Type, which is a 64-bit Integer.
The CInt(RemainingTime) is used a few places because Option Strict On won't allow assigning a bigger Integer Type (i.e. a Long 64-bit) to a smaller Integer Type (Integer is 32-bit). You have to use CInt to convert the 64-bit integer into a 32-bit integer.

So, if RemainingTime is something like 5 minutes (300 seconds),
RemainingTime - CInt(RemainingTime) is (300 - 300) so is 0.
It will always be 0.

You just need to convert the Seconds into a TimeSpan, and then the TimeSpan into a Date, and then the Date into "mm:ss", which could be like:
Label3.Text = New DateTime(TimeSpan.FromSeconds(RemainingTime).Ticks).ToString("mm:ss")
Two lines added to the Timer1 tick event in the previous example (plus the added label3)
  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    RemainingTime = DateDiff(DateInterval.Second, Now, AlarmTime)
    If RemainingTime <= 0 Then
      Label3.Text = "00:00"               'new code, set countdown display to 00:00
      '     ProgressBar1.Value = 0
      ProgressBar1.Value = ProgressBar1.Maximum
      MsgBox("time is up")
      'new code, set countdown display
      Label3.Text = New DateTime(TimeSpan.FromSeconds(RemainingTime).Ticks).ToString("mm:ss")
      '      ProgressBar1.Value = CInt(RemainingTime)
      ProgressBar1.Value = ProgressBar1.Maximum - CInt(RemainingTime)
    End If
  End Sub
p.s. I guess I didn't really notice it the first time, but looking at the code again (especially since you use the Format function), I guess in .Net it would be preferable to not use the Format function as you did in the Timer2's Tick event, but rather used the object's .ToString method.
  Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
    Label1.Text = TimeOfDay.ToString("HH:mm:ss") 'Format(TimeOfDay, "HH:mm:ss")
  End Sub
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-06-2014 at 08:28 PM.
Reply With Quote