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

x
?
Solved

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

Posted on 2009-07-07
6
Medium Priority
?
226 Views
Last Modified: 2013-11-27
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.

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
  • 3
  • 2
6 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 1000 total points
ID: 24799072
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
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 1000 total points
ID: 24799177
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
 

Author Comment

by:technicaltrader
ID: 24799224
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:technicaltrader
ID: 24799231
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
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 24799237
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
 

Author Closing Comment

by:technicaltrader
ID: 31600860
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

609 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