Solved

Message posting for specific times of day in Visual Basic 2008 Express

Posted on 2009-07-08
2
184 Views
Last Modified: 2013-11-27
Right now I am using the code below to post a message between 12 and 1.

How would I post the same message but only for the times of 12:00pm to 12:15pm as same Monday - Friday?

Tried several things using timers but it isn't working. Thanks in advance!...
Dim now As DateTime = DateTime.Now

        If Not (now.DayOfWeek = DayOfWeek.Saturday Or now.DayOfWeek = DayOfWeek.Sunday) Then

            If now.Hour = 12 Then

                lblMessage.Text = "Lunch Time"

            Else

                lblMessage.Text = String.Empty

            End If

        End If

Open in new window

0
Comment
Question by:technicaltrader
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Try something like this:
Public Class Form1
 

    Private LunchTimeSpanStart As New TimeSpan(12, 0, 0)

    Private LunchTimeSpanEnd As New TimeSpan(12, 15, 0)
 

    Private WithEvents tmr As System.Windows.Forms.Timer
 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        tmr = New System.Windows.Forms.Timer

        tmr.Interval = 1000

        tmr.Start()

    End Sub
 

    Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick

        Select Case DateTime.Now.DayOfWeek

            Case DayOfWeek.Sunday, DayOfWeek.Saturday

                lblMessage.Text = String.Empty
 

            Case Else

                Dim dtNow As DateTime = DateTime.Now

                Dim LunchDateTimeStart As DateTime = DateTime.Today.Add(LunchTimeSpanStart)

                Dim LunchDateTimeEnd As DateTime = DateTime.Today.Add(LunchTimeSpanEnd)

                If dtNow >= LunchDateTimeStart AndAlso dtNow <= LunchDateTimeEnd Then

                    lblMessage.Text = "Lunch Time"

                Else

                    lblMessage.Text = String.Empty

                End If

        End Select

    End Sub
 

End Class

Open in new window

0
 

Author Closing Comment

by:technicaltrader
Comment Utility
Thank you. Some of this I was using and wasn't making sense to me. Now you have clarified some things for me!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now