Private alarmTime As Date
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.alarmTime = Date.Now.AddMinutes(10)
Me.Timer1.Start()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If alarmTime < Date.Now Then
Me.Timer1.Stop()
MessageBox.Show("Time's up.")
Else
Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now)
Me.Label1.Text = String.Format("{0}:{1:d2}:{2:d2}", _
remainingTime.Hours, _
remainingTime.Minutes, _
remainingTime.Seconds)
End If
End Sub
JohnH, you are working under a serious misconception. The Date type is an in-built VB.NET type, just like Integer, String, Char, Boolean, Double, Decimal, Single, etc. Note that all those keywords turn blue in the IDE when you type them as they are part of the VB.NET language itself. Each of those native types is implemented using a .NET Framework type. The String type is implemented using the System.String class, the Integer type is implemeted using the System.Int32 structure and the Date type is implemented using the System.DateTime structure. This means that when you declare a variable as the Date type it IS a System.DateTime object, just like when you declare a variable of type Integer it IS a System.Int32 object. In my code, every member of the Date type that I use IS a member of the System.DateTime structure. By all means look up the member listing for the System.DateTime structure and you'll see that it has Now, AddMinutes and Subtract members. The in-built VB.NET types have nothing to do with legacy support and everything to do with the standard types that every self-respecting programming language supports.JohnH said:But you use the Date data type and it's subtract method which is also legacy (VB6), so I don't see any difference to that suggestion.
Online link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vadatDate.aspThe equivalent .NET data type is System.DateTime.