Solved

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

Posted on 2009-07-07
6
219 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
  • 3
  • 2
6 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 250 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 250 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 Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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 59

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 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

13 Experts available now in Live!

Get 1:1 Help Now