Solved

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

Posted on 2009-07-07
6
220 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
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…

863 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

24 Experts available now in Live!

Get 1:1 Help Now