Results 1 to 6 of 6

Thread: Change image based on system date

  1. #1
    Join Date
    Jul 2009
    Posts
    79

    Change image based on system date

    I created an app in visual studio express 2008. I set a screen for SplashScreen with an image. I would like this picture changes depending on the season, so I went to my SplashScreen designer and found the line that corresponds to the image display:

    Code:
    Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.plus_beautiful_band
    Where plus_beautiful_band is the name of my image.

    I would like to put an If to see whether it is summer and put the beach, if it is autumn then we put leaves and so on for all season. The problem is that I do not know the code to do so. Maybe it is menu that I compare the date that corresponds to my season but I do not know the code.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Change image based on system date

    To do what? Do you know what season it is? Change the picture? The code to save an image you've posted. So I do not see what you lack

    For the season, just know the season dates:
    - Spring: March 21
    - Summer: June 21
    - Fall: September 21
    - Winter: December 21

  3. #3
    Join Date
    Jul 2009
    Posts
    79

    Re: Change image based on system date

    Thank you for your reply. In fact I miss the code to retrieve the day and month (without the year) and the solution to compare date:

    How can I tell him: - If the system date is greater than 21/03 and less than the 21/06 so ... the rest I know.

  4. #4
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Change image based on system date

    To retrieve the month and day you just need your system time in a variable of type DateTime.
    Code:
    dim Dt as DateTime
    Dt.Day 'for the day
    Dt.month 'for the month
    and you can compare a Date1.CompareTo (date2)
    Date1.CompareTo (date2)
    compares the value of this instance to a System.DateTime instance and returns an integer that indicates whether this instance is earlier, later or equal to the specified DateTime

  5. #5
    Join Date
    Jul 2009
    Posts
    79

    Re: Change image based on system date

    Code:
    Dim l_Date As DateTime
    l_Date.Day
    l_Date.Month
    Visual Studio returns me the error:
    Standard access to the property must assign the property or use its value.
    And after recovering my day and my month how I did for them together? Basically I want something like:
    Code:
    If DateSystem > 21/03 and DateSystem < 21/06 Then
           Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.image_of_spring
    Else
           If DateSystem > 21/06 and DateSystem < 21/12hen
                  Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.image_of_winter
           End If
    End If
    Except that it does not work. I'm not very good at programming, I do not understand everything

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Change image based on system date

    This is a function that returns the season for a given date:
    Code:
    Public Enum Season
         Spring
         Summer
         Autumn
         Winter
    End Enum
    Public Shared Function GetSeason(ByVal dt As DateTime) As Season
         Dim dSpring As DateTime = New DateTime(dt.Year, 3, 21)
         Dim dSummer As DateTime = New DateTime(dt.Year, 6, 21)
         Dim dAutumn As DateTime = New DateTime(dt.Year, 9, 21)
         Dim dWinter As DateTime = New DateTime(dt.Year, 12, 21)
         If dt < dSpring Then
              Return Season.Winter
         ElseIf dt < dSummer Then
              Return Season.Spring
         ElseIf dt < dAutumn Then
              Return Season.Summer
         ElseIf dt < dWinter Then
              Return Season.Autumn
         Else
              Return Season.Winter
         End If
    End Function
    To use it, you can do like this (assuming you had the resources in your application images Spring, Summer, Autumn and Winter):
    Code:
    Dim season As Season = GetSeason(DateTime.Today)
    Select Case season 
        Case Season.Spring
            Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Spring
        Case Season.Summer
            Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Summer
        Case Season.Autumn
            Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Autumn
        Case Season.Winter
            Me.MainLayoutPanel.BackgroundImage = Global.Management_Informative.My.Resources.Resources.Winter
        Case Else
            ' default case (should not occur...)
    End Select

Similar Threads

  1. Script needed to Delete Files in a Directory Based on Date
    By adaher008 via WinServerKB.com in forum Windows Server Help
    Replies: 11
    Last Post: 02-01-2012, 01:44 AM
  2. Excel: How to make a list based on the date entered
    By OttaKoo in forum Windows Software
    Replies: 5
    Last Post: 31-03-2011, 07:35 PM
  3. Delete files based on creation date?
    By Hank Arnold (MVP) in forum Windows Server Help
    Replies: 2
    Last Post: 19-10-2010, 12:55 AM
  4. Replies: 4
    Last Post: 14-05-2010, 12:16 AM
  5. Create new folder and move files based on creation date
    By dstiff in forum Windows Server Help
    Replies: 3
    Last Post: 13-11-2009, 05:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,502,281.27090 seconds with 17 queries