Reputation: 55
Don't forget the only thing i need is time NOT date just time
I save the value from datetimepicker ("hh:mm") to my.settings like this .
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Settings.firstStart = DateTimePicker1.Value.TimeOfDay
My.Settings.firstEnd = DateTimePicker2.Value.TimeOfDay
My.Settings.secondStart = DateTimePicker3.Value.TimeOfDay
My.Settings.secondEnd = DateTimePicker4.Value.TimeOfDay
My.Settings.Save()
End Sub
After that i compare the value from mysettings to current time like this
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
If My.Settings.firstStart <= currentTime AndAlso currentTime <= My.Settings.firstEnd Then
Label2.Text = "First Class"
ElseIf My.Settings.secondStart <= currentTime AndAlso currentTime <= My.Settings.secondEnd Then
Label2.Text = "Second Class"
Else
Label2.Text = "Free Time"
End If
End Sub
Why the label2.text don't want to change even when the currenttime goes in range for (" Second Class")
It will but when i reopen the application it will show "Second Class" and label2.text won't change till i nexttime reopen application no matter how much time passed.
Next thing how can i load data from my.settings to my datetimepicker. Don't forget only important thing is TIME not date i don't need to use date at all
Upvotes: 1
Views: 596
Reputation: 55
Put the value from currentTime
to TimerTick
event
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer.Tick
TextBox1.Text = Date.Now.ToString("hh:mm")
Dim currentTime As TimeSpan = Date.Now.TimeOfDay
If My.Settings.firstStart <= currentTime AndAlso currentTime <= My.Settings.firstEnd Then
Label2.Text = "First Class"
ElseIf My.Settings.secondStart <= currentTime AndAlso currentTime <= My.Settings.secondEnd Then
Label2.Text = "Second Class"
Else
Label2.Text = "Free Time"
End If
End Sub
Upvotes: 0