How to post a message 5 days a week only Visual basic 2008

Hi.

Example:
Using VB2008 Express, how would I go about posting a message "Lunch Time" in a TextBox or status bar at 12:00pm and stop the message at 1:00pm Monday - friday only.

I know how to use the timers for posting it for one hour, I don't know how to use the "Date method" as I have seen many refer to. Or best said, I do not know how to code for a message to appear at a set day of the week and time of the day.


Thank you in advance.

technicaltraderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kevin CrossChief Technology OfficerCommented:
You can use the DayOfWeek property of the DateTime data type.  This is not greatest logic, but hopefully shows you the usage:
Dim now As DateTime = DateTime.Now
        If Not (now.DayOfWeek = DayOfWeek.Saturday Or now.DayOfWeek = DayOfWeek.Sunday) Then
            MsgBox("Lunch Time!")
        Else
            MsgBox("Weekend!")
        End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
guru_samiCommented:
Little modification to what mwvisa1 provided...

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

Now if you want this automated...then yes you might want to use some timer to trigger this code or some service kind of thing...not sure exactly how it would go.
0
technicaltraderAuthor Commented:
Got the logic and making it work for me so far. Changing the date on my computer clock to check it. All is good. thank you!

This is how I used it so far:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventsArgs) handles timer1.Tick
Dim now As DateTime = DateTime.Now
        If Not (now.DayOfWeek = DayOfWeek.Saturday Or now.DayOfWeek = DayOfWeek.Sunday) Then
            StatusBar1.Text = "Lunch Time!"
        Else
            StatusBar1.Text = "Weekend!"
        End If


How is it that I control this to display message at specific times in the day with the day of the week? (Example: 12:00pm to 1:00pm)

Far as I know, I can only use the Timer to control the duration the message is displayed. So if duration is 1 hour I would set the Interval to 3,600,000. Don't know how to control the time of day part.

Thanks again!...
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

technicaltraderAuthor Commented:
Shoot, didn't see your post guru_sami! I will try that suggestion first unless you see my last question and thought something different. Will try that suggestion too.

Thanks!
0
Kevin CrossChief Technology OfficerCommented:
See Guru_Sami's comment.  It shows you with hour portion also.  Thought you already had that; therefore, I didn't post it.  And my "Weekend!" was just to make it clear what I was doing, in your case where you are showing a status OR not, String.Empty may work better for you which is also shown in Guru_Sami's comment.

Best regards,
Kevin
0
technicaltraderAuthor Commented:
Thank you both. Loved the addition of the "Weekend!" message (Could tell some passion for the weekend too in that message! LOL) Believe this will get me on my way. Thank you so much!... I was stagnant in this solution quest.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.