[RESOLVED] Calculating the first Sunday of Advent-VBForums
Results 1 to 10 of 10

Thread: [RESOLVED] Calculating the first Sunday of Advent

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Gran Canaria, Spain.
    Posts
    83

    Resolved [RESOLVED] Calculating the first Sunday of Advent

    Hello, I am trying to calculate the first Sunday of Advent in VB6 (for any future year).

    Advent Sunday is the fourth Sunday before Christmas Day.
    This is equivalent to the Sunday nearest to St. Andrew's Day, 30 November.

    So for example St. Andrew's Day this year is day #334
    Therefore this years Advent Sunday is 03/12/17 (which is day #337)

    How can I find this day# automatically in VB6 for future years?

    Thanks in advance



    *Note*: I have been playing with code of my own of to sort this.
    And have just been tying myself in Knots
    Last edited by BriansBrain; Dec 3rd, 2017 at 11:45 AM. Reason: RESOLVED

  2. #2
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    846

    Re: Calculating the first Sunday of Advent

    Hi Brain

    this is with Dateformat Germany "dd.mm.yyyy", you will have to work
    on the Format you want

    Code:
    Private Function GetViertenAdvent(JahrA As Long) As Date
      Dim i As Long
     
      For i = 24 To 1 Step -1
        If Format$(i & ".12." & JahrA, "ddd") = "So" Then
          GetViertenAdvent = Format$(i & ".12." & JahrA, "dd.mm.yyyy")
          Exit For
        End If
      Next i
    End Function
    
    Private Sub Command2_Click()
    
    Dim JahrA As Long
    JahrA = 2017
    
    List2.AddItem "4. Advent " & GetViertenAdvent(JahrA)
    
    List2.AddItem "3. Advent " & DateAdd("d", -7, GetViertenAdvent(JahrA))
     
    List2.AddItem "2. Advent" & DateAdd("d", -14, GetViertenAdvent(JahrA))
     
    List2.AddItem "1. Advent " & DateAdd("d", -21, GetViertenAdvent(JahrA))
    End Sub
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Gran Canaria, Spain.
    Posts
    83

    Re: Calculating the first Sunday of Advent

    Thanks for the quick reply Chris,

    Using your code as is I get this result in the ListBox...

    Code:
    4. Advent 00:00:00
    3. Advent 23/12/1899
    2. Advent 16/12/1899
    1. Advent 09/12/1899

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,083

    Re: Calculating the first Sunday of Advent

    Here's my take. If it has a bug I'm sure it can easily be fixed.

    Code:
    Private Function AdventSunday(ByVal Christmas As Date) As Date
        AdventSunday = DateAdd("ww", -4, DateAdd("d", -(Weekday(Christmas) - 1), Christmas))
    End Function
    Name:  sshot.png
Views: 71
Size:  3.5 KB
    Attached Files Attached Files

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Posts
    18,083

    Re: Calculating the first Sunday of Advent

    Code:
    Private Function AdventSunday(ByVal Christmas As Date) As Date
        Dim Weeks As Integer
    
        Weeks = IIf(Weekday(Christmas) = vbSunday, -4, -3)
        AdventSunday = DateAdd("ww", Weeks, DateAdd("d", -(Weekday(Christmas) - 1), Christmas))
    End Function
    I had to look up "Advent" but maybe this is it?

    Name:  sshot.png
Views: 57
Size:  3.6 KB
    Last edited by dilettante; Dec 3rd, 2017 at 11:23 AM.

  6. #6
    Fanatic Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    846

    Re: Calculating the first Sunday of Advent

    Quote Originally Posted by BriansBrain View Post
    Thanks for the quick reply Chris,

    Using your code as is I get this result in the ListBox...

    Code:
    4. Advent 00:00:00
    3. Advent 23/12/1899
    2. Advent 16/12/1899
    1. Advent 09/12/1899

    how did you change the Code ?
    you have to change the Dateformat

    dillettante's code looks good to me

    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Gran Canaria, Spain.
    Posts
    83

    Re: Calculating the first Sunday of Advent

    OK Chris If I mod the Function to this it works...

    Code:
    Private Function GetViertenAdvent(JahrA As Long) As Date
      Dim i As Long
     
      For i = 24 To 1 Step -1
        If Format(i & "/12/" & JahrA, "dddd") = "Sunday" Then
          GetViertenAdvent = Format(i & "/12/" & JahrA, "dd/mm/yyyy")
          Exit For
        End If
      Next i
    End Function
    I get ...
    Code:
    4. Advent 24/12/2017
    3. Advent 17/12/2017
    2. Advent 10/12/2017
    1. Advent 03/12/2017
    Big thanks again Chris
    Last edited by BriansBrain; Dec 3rd, 2017 at 11:59 AM.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Gran Canaria, Spain.
    Posts
    83

    Re: Calculating the first Sunday of Advent

    Thanks dilettante

    Your code using your moded Function seems to work Fine

    Thanks to everyone who Looked at this

  9. #9
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,359

    Re: [RESOLVED] Calculating the first Sunday of Advent

    Just another one on the pile:

    Code:
    Private Function FirstAdvent(ByVal Year As Long) As Date
      FirstAdvent = DateSerial(Year, 12, 4 - Weekday(DateSerial(Year, 12, 24)))
    End Function
    Olaf

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Oct 2009
    Location
    Gran Canaria, Spain.
    Posts
    83

    Re: [RESOLVED] Calculating the first Sunday of Advent

    Quote Originally Posted by Schmidt View Post
    Just another one on the pile:

    Olaf
    Works perfect

    Thanks again Olaf

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.