Visual Basic - Reset at 00:00
I've got an question about resetting a 开发者_如何学Pythonlabel every night at the same time.
What do i mean: 1. when starting the program my label.text = 750 every time someone clicks a button the label text reduces with 1 so 750 749 748 etc etc
but now i want that every day at 00:00 the label's text resets to 750.
is that possible??
Javed Akram's comment is correct -- none of this is going to matter, if the program isn't running at midnight.
However, for what you actually asked for - resetting a count at midnight - consider adding a TIMER to your project. You really only need the timer to click once a day (at midnight):
Private Sub SetInterval()
' Calculate how many milliseconds until the timer ticks again:
' Start by calculating the number of seconds between now and tomorrow.
' Multiply by 1000, then add 50 more -- this is to make sure that the
' timer runs 1/50 of a second AFTER midnight, so that we can
' re-calculate the interval again at that time.
Timer1.Interval = CInt( _
DateDiff(DateInterval.Second, Now, Today.AddDays(1)) * 1000 + 50)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
' Reset the interval, so that we run again tomorrow at midnight.
SetInterval()
' Now, reset your label
Label1.Text = "750" ' Or whatever else needs to happen to reset the count
End Sub
You'll also need to add a call to SetInterval in Form_Load (or whatever your program initialization is), to set up the very first interval.
On an almost completely UN-related note, does anyone know why the Date class has an AddMilliseconds function, but Microsoft.VisualBasic.DateInterval (and therefore the DateDiff function) doesn't have Milliseconds? It's non-symmetrical.
精彩评论