Search code examples
vb.nettimer

Can I make a message box appear if a textbox time is 5 minutes before system time?


I am trying to create a reminder system for my break schedule (because for some reason the tech company I work for does not have one in our scheduling system /facepalm)

I can make it work IF the time I write in the textbox for my break matches the system time. What I would like it to do is change it so it pops up once, 5 minutes before and then again when it matches the system time. Here is what i have so far for the on time reminder:

Sub Timer1Tick(sender As Object, e As EventArgs)
DaClock.Text = Format(Now, "h:mm")

For the sake of simplicity ^

If Coffee.Text = "DaClock.Text" And reminder.Checked = True Then
    Coffee.Text = (Coffee.Text + " Over")
    Coffee.Enabled  = False
    MsgBox("Break Time", MsgBoxStyle.Information, "break")
Else If Coffee.Text = DaClock.Text Then
    Coffee.Text = (Coffee.Text + " Over")
    Coffee.Enabled  = False 
End If
End Sub

I find that I am not able to figure out how to get the reminder to pop up 5 minutes before.

edit Oh it may not be relevant but DaClock is an invisible Label

Update I was able to set up a secont label and a string with 5 minutes added so the event will trigger 5 minutes early but now i am having formatting issues:

        Dim MyTime As String
        MyTime = TimeOfDay.AddMinutes(5)

        D5Clock.Text = Format(MyTime, "h:mm")

But all it shows in the Label is h:mm. If i choose not to format it and shows normally, (eg: 6:30:54 PM) but the formatting is important to make sure my break entries trigger as we are only using the h:mm (eg 6:30) in the fields.


Solution

  • Figured it out by running two clocks simultaneously and calling each one so it will happen 5 minutes early and then again on time.

            D5Clock.Text = Format(TimeOfDay.AddMinutes(5), "h:mm")
            DaClock.Text = Format(TimeOfDay, "h:mm")
    
    

    whew