Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2009-07-08
2
Medium Priority
?
221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

610 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