Calculate Easter Sunday

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    Calculate Easter Sunday

    Hi, I found this code on the web.. it was c# and I ran it through a c# to vb
    converter( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
    ....but it is not correct.. what did it or I do incorrectly?
    this is the c# code
    public static void EasterSunday(in t year, ref int month, ref int day)
    {
    int g = year % 19;
    int c = year / 100;
    int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
    + 19 * g + 15) % 30;
    int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
    (int)(29 / (h + 1)) * (int)((21 - g) / 11));

    day = i - ((year + (int)(year / 4) +
    i + 2 - c + (int)(c / 4)) % 7) + 28;
    month = 3;

    if (day 31)
    {
    month++;
    day -= 31;
    }
    }this is the vb codePublic Shared Sub EasterSunday(By Val year As Integer,
    ByRef month As Integer, ByRef day As Integer)

    Dim g As Integer = year Mod 19

    Dim c As Integer = CInt(year / 100)

    Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod
    30)

    Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) * CInt(21 - g)
    / 11)

    day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7) + 28

    month = 3

    If day 31 Then

    month += 1

    day -= 31

    End If

    End Sub


  • Jack Jackson

    #2
    Re: Calculate Easter Sunday

    On Sun, 13 Apr 2008 00:34:59 -0400, "Brian"
    <bsgallatin@com munity.nospamwr ote:
    >Hi, I found this code on the web.. it was c# and I ran it through a c# to vb
    >converter( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
    >...but it is not correct.. what did it or I do incorrectly?
    >this is the c# code
    >public static void EasterSunday(in t year, ref int month, ref int day)
    >{
    int g = year % 19;
    int c = year / 100;
    int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
    + 19 * g + 15) % 30;
    int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
    (int)(29 / (h + 1)) * (int)((21 - g) / 11));
    >
    day = i - ((year + (int)(year / 4) +
    i + 2 - c + (int)(c / 4)) % 7) + 28;
    month = 3;
    >
    if (day 31)
    {
    month++;
    day -= 31;
    }
    >}this is the vb codePublic Shared Sub EasterSunday(By Val year As Integer,
    >ByRef month As Integer, ByRef day As Integer)
    >
    >Dim g As Integer = year Mod 19
    >
    >Dim c As Integer = CInt(year / 100)
    >
    >Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod
    >30)
    >
    >Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) * CInt(21 - g)
    >/ 11)
    >
    >day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7) + 28
    >
    >month = 3
    >
    >If day 31 Then
    >
    >month += 1
    >
    >day -= 31
    >
    >End If
    >
    >End Sub
    >
    The C# code is strange, none of the (int) casts are needed. That
    makes me wonder if the C# code itself is correct. Have you tried
    running it?

    However, the conversion is incorrect. In C# the / operator when used
    with Integers does integer division. The corresponding operator in VB
    is \. In VB / does floating point division regardless of the type of
    the arguments. Doing floating point divisions and then periodically
    converting to Integer may give different results in some cases. The
    correct conversion would replace all of the / operators with \. The
    Cint() casts can also be removed.

    Comment

    • Brian

      #3
      Re: Calculate Easter Sunday

      Thanks that did it... didn't relize the difereance between / \

      "Jack Jackson" <jjackson@cinno vations.netwrot e in message
      news:5d8304l90m cuffocp65fqnjkj j8900m5oa@4ax.c om...
      On Sun, 13 Apr 2008 00:34:59 -0400, "Brian"
      <bsgallatin@com munity.nospamwr ote:
      >
      >>Hi, I found this code on the web.. it was c# and I ran it through a c# to
      >>vb
      >>converter( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
      >>...but it is not correct.. what did it or I do incorrectly?
      >>this is the c# code
      >>public static void EasterSunday(in t year, ref int month, ref int day)
      >>{
      > int g = year % 19;
      > int c = year / 100;
      > int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
      > + 19 * g + 15) % 30;
      > int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
      > (int)(29 / (h + 1)) * (int)((21 - g) / 11));
      >>
      > day = i - ((year + (int)(year / 4) +
      > i + 2 - c + (int)(c / 4)) % 7) + 28;
      > month = 3;
      >>
      > if (day 31)
      > {
      > month++;
      > day -= 31;
      > }
      >>}this is the vb codePublic Shared Sub EasterSunday(By Val year As Integer,
      >>ByRef month As Integer, ByRef day As Integer)
      >>
      >>Dim g As Integer = year Mod 19
      >>
      >>Dim c As Integer = CInt(year / 100)
      >>
      >>Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod
      >>30)
      >>
      >>Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) * CInt(21 -
      >>g)
      >>/ 11)
      >>
      >>day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7) +
      >>28
      >>
      >>month = 3
      >>
      >>If day 31 Then
      >>
      >>month += 1
      >>
      >>day -= 31
      >>
      >>End If
      >>
      >>End Sub
      >>
      >
      The C# code is strange, none of the (int) casts are needed. That
      makes me wonder if the C# code itself is correct. Have you tried
      running it?
      >
      However, the conversion is incorrect. In C# the / operator when used
      with Integers does integer division. The corresponding operator in VB
      is \. In VB / does floating point division regardless of the type of
      the arguments. Doing floating point divisions and then periodically
      converting to Integer may give different results in some cases. The
      correct conversion would replace all of the / operators with \. The
      Cint() casts can also be removed.
      >

      Comment

      • Just_a_fan@home.net

        #4
        Re: Calculate Easter Sunday

        Go get my code from PSC. Search on Holidate in the VB section. It does
        all that and ever so much more.

        Mike

        On Sun, 13 Apr 2008 00:34:59 -0400, in
        microsoft.publi c.dotnet.langua ges.vb "Brian"
        <bsgallatin@com munity.nospamwr ote:
        >Hi, I found this code on the web.. it was c# and I ran it through a c# to vb
        >converter( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
        >...but it is not correct.. what did it or I do incorrectly?
        >this is the c# code
        >public static void EasterSunday(in t year, ref int month, ref int day)
        >{
        int g = year % 19;
        int c = year / 100;
        int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
        + 19 * g + 15) % 30;
        int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
        (int)(29 / (h + 1)) * (int)((21 - g) / 11));
        >
        day = i - ((year + (int)(year / 4) +
        i + 2 - c + (int)(c / 4)) % 7) + 28;
        month = 3;
        >
        if (day 31)
        {
        month++;
        day -= 31;
        }
        >}this is the vb codePublic Shared Sub EasterSunday(By Val year As Integer,
        >ByRef month As Integer, ByRef day As Integer)
        >
        >Dim g As Integer = year Mod 19
        >
        >Dim c As Integer = CInt(year / 100)
        >
        >Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod
        >30)
        >
        >Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) * CInt(21 - g)
        >/ 11)
        >
        >day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7) + 28
        >
        >month = 3
        >
        >If day 31 Then
        >
        >month += 1
        >
        >day -= 31
        >
        >End If
        >
        >End Sub
        >

        Comment

        • Brian

          #5
          Re: Calculate Easter Sunday

          what is PSC?
          <Just_a_fan@hom e.netwrote in message
          news:pok304htit 8pnrhctisuogq28 0leuaag8a@4ax.c om...
          Go get my code from PSC. Search on Holidate in the VB section. It does
          all that and ever so much more.
          >
          Mike
          >
          On Sun, 13 Apr 2008 00:34:59 -0400, in
          microsoft.publi c.dotnet.langua ges.vb "Brian"
          <bsgallatin@com munity.nospamwr ote:
          >
          >>Hi, I found this code on the web.. it was c# and I ran it through a c# to
          >>vb
          >>converter( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
          >>...but it is not correct.. what did it or I do incorrectly?
          >>this is the c# code
          >>public static void EasterSunday(in t year, ref int month, ref int day)
          >>{
          > int g = year % 19;
          > int c = year / 100;
          > int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
          > + 19 * g + 15) % 30;
          > int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
          > (int)(29 / (h + 1)) * (int)((21 - g) / 11));
          >>
          > day = i - ((year + (int)(year / 4) +
          > i + 2 - c + (int)(c / 4)) % 7) + 28;
          > month = 3;
          >>
          > if (day 31)
          > {
          > month++;
          > day -= 31;
          > }
          >>}this is the vb codePublic Shared Sub EasterSunday(By Val year As Integer,
          >>ByRef month As Integer, ByRef day As Integer)
          >>
          >>Dim g As Integer = year Mod 19
          >>
          >>Dim c As Integer = CInt(year / 100)
          >>
          >>Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod
          >>30)
          >>
          >>Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) * CInt(21 -
          >>g)
          >>/ 11)
          >>
          >>day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7) +
          >>28
          >>
          >>month = 3
          >>
          >>If day 31 Then
          >>
          >>month += 1
          >>
          >>day -= 31
          >>
          >>End If
          >>
          >>End Sub
          >>
          >

          Comment

          • Just_a_fan@home.net

            #6
            Re: Re: Calculate Easter Sunday

            PSC = http://www.Planet-Source-Code.com

            Thought everyone knew. Excellent resource.

            Mike

            On Sun, 13 Apr 2008 13:36:44 -0400, in
            microsoft.publi c.dotnet.langua ges.vb "Brian"
            <bsgallatin@com munity.nospamwr ote:
            >what is PSC?
            ><Just_a_fan@ho me.netwrote in message
            >news:pok304hti t8pnrhctisuogq2 80leuaag8a@4ax. com...
            >Go get my code from PSC. Search on Holidate in the VB section. It does
            >all that and ever so much more.
            >>
            >Mike
            >>
            >On Sun, 13 Apr 2008 00:34:59 -0400, in
            >microsoft.publ ic.dotnet.langu ages.vb "Brian"
            ><bsgallatin@co mmunity.nospamw rote:
            >>
            >>>Hi, I found this code on the web.. it was c# and I ran it through a c# to
            >>>vb
            >>>converter( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
            >>>...but it is not correct.. what did it or I do incorrectly?
            >>>this is the c# code
            >>>public static void EasterSunday(in t year, ref int month, ref int day)
            >>>{
            >> int g = year % 19;
            >> int c = year / 100;
            >> int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
            >> + 19 * g + 15) % 30;
            >> int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
            >> (int)(29 / (h + 1)) * (int)((21 - g) / 11));
            >>>
            >> day = i - ((year + (int)(year / 4) +
            >> i + 2 - c + (int)(c / 4)) % 7) + 28;
            >> month = 3;
            >>>
            >> if (day 31)
            >> {
            >> month++;
            >> day -= 31;
            >> }
            >>>}this is the vb codePublic Shared Sub EasterSunday(By Val year As Integer,
            >>>ByRef month As Integer, ByRef day As Integer)
            >>>
            >>>Dim g As Integer = year Mod 19
            >>>
            >>>Dim c As Integer = CInt(year / 100)
            >>>
            >>>Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15) Mod
            >>>30)
            >>>
            >>>Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) * CInt(21 -
            >>>g)
            >>>/ 11)
            >>>
            >>>day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7) +
            >>>28
            >>>
            >>>month = 3
            >>>
            >>>If day 31 Then
            >>>
            >>>month += 1
            >>>
            >>>day -= 31
            >>>
            >>>End If
            >>>
            >>>End Sub
            >>>
            >>
            >

            Comment

            • Brian

              #7
              Re: Re: Calculate Easter Sunday

              thanks.. I'll go check it out...

              <Just_a_fan@hom e.netwrote in message
              news:0ta6049cme 9a42ovfduhef33v 1u99kgaf7@4ax.c om...
              PSC = http://www.Planet-Source-Code.com
              >
              Thought everyone knew. Excellent resource.
              >
              Mike
              >
              On Sun, 13 Apr 2008 13:36:44 -0400, in
              microsoft.publi c.dotnet.langua ges.vb "Brian"
              <bsgallatin@com munity.nospamwr ote:
              >
              >>what is PSC?
              >><Just_a_fan@h ome.netwrote in message
              >>news:pok304ht it8pnrhctisuogq 280leuaag8a@4ax .com...
              >>Go get my code from PSC. Search on Holidate in the VB section. It does
              >>all that and ever so much more.
              >>>
              >>Mike
              >>>
              >>On Sun, 13 Apr 2008 00:34:59 -0400, in
              >>microsoft.pub lic.dotnet.lang uages.vb "Brian"
              >><bsgallatin@c ommunity.nospam wrote:
              >>>
              >>>>Hi, I found this code on the web.. it was c# and I ran it through a c#
              >>>>to
              >>>>vb
              >>>>converter ( http://labs.developerfusion.co.uk/co...arp-to-vb.aspx
              >>>>...but it is not correct.. what did it or I do incorrectly?
              >>>>this is the c# code
              >>>>public static void EasterSunday(in t year, ref int month, ref int day)
              >>>>{
              >>> int g = year % 19;
              >>> int c = year / 100;
              >>> int h = h = (c - (int)(c / 4) - (int)((8 * c + 13) / 25)
              >>> + 19 * g + 15) % 30;
              >>> int i = h - (int)(h / 28) * (1 - (int)(h / 28) *
              >>> (int)(29 / (h + 1)) * (int)((21 - g) / 11));
              >>>>
              >>> day = i - ((year + (int)(year / 4) +
              >>> i + 2 - c + (int)(c / 4)) % 7) + 28;
              >>> month = 3;
              >>>>
              >>> if (day 31)
              >>> {
              >>> month++;
              >>> day -= 31;
              >>> }
              >>>>}this is the vb codePublic Shared Sub EasterSunday(By Val year As
              >>>>Integer,
              >>>>ByRef month As Integer, ByRef day As Integer)
              >>>>
              >>>>Dim g As Integer = year Mod 19
              >>>>
              >>>>Dim c As Integer = CInt(year / 100)
              >>>>
              >>>>Dim h As Integer = CInt((c - c / 4 - (8 * c + 13) / 25 + 19 * g + 15)
              >>>>Mod
              >>>>30)
              >>>>
              >>>>Dim i As Integer = CInt(h - CInt(h / 28) * CInt(29 / (h + 1)) *
              >>>>CInt(21 -
              >>>>g)
              >>>>/ 11)
              >>>>
              >>>>day = i - ((year + CInt((year / 4)) + i + 2 - c + CInt((c / 4))) Mod 7)
              >>>>+
              >>>>28
              >>>>
              >>>>month = 3
              >>>>
              >>>>If day 31 Then
              >>>>
              >>>>month += 1
              >>>>
              >>>>day -= 31
              >>>>
              >>>>End If
              >>>>
              >>>>End Sub
              >>>>
              >>>
              >>
              >

              Comment

              Working...