1

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

  • why are you using ElseIf to compare 2 different things? they are not mutually exclusive – Ňɏssa Pøngjǣrdenlarp Sep 04 '14 at 12:10
  • Do you have Option Strict On? (You should have if not) – Matt Wilko Sep 04 '14 at 12:11
  • @plutonix there is more condition's which come after this i copied just two of them – Anel_Hodzic Sep 04 '14 at 12:47
  • `currentTime` should probably be set in the Timer event if you are evaluating the actual current time. otherwise there is no reason for a Timer. – Ňɏssa Pøngjǣrdenlarp Sep 04 '14 at 12:51
  • @Plutonix Can't belive that i missed that. Thank you for your notice. Just another thing how to load data from settings to DateTimePicker . Take a look on the code above. On formload event. Keep in mind that i just need time not date – Anel_Hodzic Sep 04 '14 at 13:08
  • `Just another thing` == new question with relevant code; there are serious flaws with the code (or your concept) judging by `I save the value from datetimepicker ("hh:mm")` The DTP value is a DateTime type but "hh:mm" is string, so we have no idea of the data/type actually being used or used correctly in evaluations. – Ňɏssa Pøngjǣrdenlarp Sep 04 '14 at 13:15

1 Answers1

0

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