Results 1 to 6 of 6

Thread: How to change label based on day?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2021
    Posts
    2

    Thumbs up How to change label based on day?

    Hey guys. Sorry for my English.
    I'm new to VB.Net (and programming in general) and I'm making a simple program where I work with the help of the internet.

    I have a prominent Label at the top of this program, and I need it to be shown only on certain days, ie:

    If today is the 1st, 5th or 16th (of any month) Label1 displays the message "ALERT! Today has a monthly schedule!"

    If today is (last day of current month), 04 or 15 (of any month) Label1 displays the message "ALERT! Monthly schedule for dawn!"


    Can anyone help me build this? Thank you.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: How to change label based on day?

    vb.net Code:
    1. Dim alertMessage As String = Nothing
    2. Dim currentDate = Date.Today
    3.  
    4. Select Case currentDate.Day
    5.     Case 1, 5, 16
    6.         alertMessage = "ALERT! Today has a monthly schedule!"
    7.     Case 4, 15, Date.DaysInMonth(currentDate.Year, currentDate.Month)
    8.         alertMessage = "ALERT! Monthly schedule for dawn!"
    9. End Select
    10.  
    11. Label1.Text = alertMessage
    12. Label1.Visible = (Label1.Text <> String.Empty)

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2021
    Posts
    2

    Resolved Re: How to change label based on day?

    Quote Originally Posted by jmcilhinney View Post
    vb.net Code:
    1. Dim alertMessage As String = Nothing
    2. Dim currentDate = Date.Today
    3.  
    4. Select Case currentDate.Day
    5.     Case 1, 5, 16
    6.         alertMessage = "ALERT! Today has a monthly schedule!"
    7.     Case 4, 15, Date.DaysInMonth(currentDate.Year, currentDate.Month)
    8.         alertMessage = "ALERT! Monthly schedule for dawn!"
    9. End Select
    10.  
    11. Label1.Text = alertMessage
    12. Label1.Visible = (Label1.Text <> String.Empty)
    Dude, I don't even know how to thank you. It was fast and accurate. My first time on the forum was already worth it. It worked out. Thank you!

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: How to change label based on day?

    Quote Originally Posted by digitaldrop View Post
    Dude, I don't even know how to thank you.
    You can't go wrong with chocolate.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    24,265

    Re: How to change label based on day?

    Quote Originally Posted by jmcilhinney View Post
    You can't go wrong with chocolate.
    Dude!!! You’re cheap

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,648

    Re: How to change label based on day?

    Quote Originally Posted by .paul. View Post
    Dude!!! You’re cheap
    I get that a lot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width