Solved

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

Posted on 2009-07-08
2
199 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
ID: 24809595
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
ID: 31601341
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

839 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