locked
Help with Conditional Date Formatting RRS feed

  • Question

  • I am frustrated that I cannot solve this seemingly easy problem: 

    Here's the code: 

     If Date.Now.Day = vbSaturday Then
          Label6.Visible = False
          Label8.Visible = True
          Label7.Visible = False
          Label8.Text = "Weekends throw calculations off for school days. Will appear again on Monday!"
     If Date.Now.Day = vbMonday Then
          Label6.Visible = True
          Label8.Visible = False
          Label7.Visible = True
     End If
    
    I want label 8 to ONLY show up on Saturday or Sunday, and labels 6 & 7 to show up Mon-Fri. I am unsure of how to get this to work. Your help will be greatly appreciated!

    Saturday, September 25, 2010 9:09 PM

Answers

  • Labels 6 & 7 refuse to hide and 8 won't display even though TODAY is Saturday. I know how to use else and ElseIf, what I DON'T know is how to set up the proper date string to make the labels hide ONLY on saturday, and to have them show M-F.


    See if this helps:

        Dim tDate As DateTime = Today
    
        If tDate.DayOfWeek = DayOfWeek.Saturday Or tDate.DayOfWeek = DayOfWeek.Sunday Then
    
        Else
    
        End If
    
    Saturday, September 25, 2010 9:26 PM

All replies

  • I think you want "ElseIf"

    If ...

    ElseIf ...

    End If

    Saturday, September 25, 2010 9:11 PM
  • Labels 6 & 7 refuse to hide and 8 won't display even though TODAY is Saturday. I know how to use else and ElseIf, what I DON'T know is how to set up the proper date string to make the labels hide ONLY on saturday, and to have them show M-F.
    Saturday, September 25, 2010 9:19 PM
  • Labels 6 & 7 refuse to hide and 8 won't display even though TODAY is Saturday. I know how to use else and ElseIf, what I DON'T know is how to set up the proper date string to make the labels hide ONLY on saturday, and to have them show M-F.


    See if this helps:

        Dim tDate As DateTime = Today
    
        If tDate.DayOfWeek = DayOfWeek.Saturday Or tDate.DayOfWeek = DayOfWeek.Sunday Then
    
        Else
    
        End If
    
    Saturday, September 25, 2010 9:26 PM
  • IT WORKS! I knew it was extremely simple, but I just couldn't figure this one out ;).
    Saturday, September 25, 2010 9:33 PM
  • IT WORKS! I knew it was extremely simple, but I just couldn't figure this one out ;).

    Glad it helped. :)
    Saturday, September 25, 2010 9:34 PM