Board index » Visual Studio » Calculate Easter Sunday

Calculate Easter Sunday

Visual Studio123
Hi, I found this code on the web.. it was c# and I ran it through a c# to vb

converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

...but it is not correct.. what did it or I do incorrectly?

this is the c# code

public static void EasterSunday(int 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(ByVal 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


-
 

Re:Calculate Easter Sunday

On Sun, 13 Apr 2008 00:34:59 -0400, "Brian"

<bsgallatin@community.nospam>wrote:



Quote
Hi, I found this code on the web.. it was c# and I ran it through a c# to vb

converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

...but it is not correct.. what did it or I do incorrectly?

this is the c# code

public static void EasterSunday(int 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(ByVal 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.



-

Re:Calculate Easter Sunday

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



"Jack Jackson" <jjackson@cinnovations.net>wrote in message

Quote
On Sun, 13 Apr 2008 00:34:59 -0400, "Brian"

<bsgallatin@community.nospam>wrote:



>Hi, I found this code on the web.. it was c# and I ran it through a c# to

>vb

>converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

>...but it is not correct.. what did it or I do incorrectly?

>this is the c# code

>public static void EasterSunday(int 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(ByVal 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.







-

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.public.dotnet.languages.vb "Brian"

<bsgallatin@community.nospam>wrote:



Quote
Hi, I found this code on the web.. it was c# and I ran it through a c# to vb

converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

...but it is not correct.. what did it or I do incorrectly?

this is the c# code

public static void EasterSunday(int 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(ByVal 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





-

Re:Calculate Easter Sunday

what is PSC?

<Just_a_fan@home.net>wrote in message

Quote
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.public.dotnet.languages.vb "Brian"

<bsgallatin@community.nospam>wrote:



>Hi, I found this code on the web.. it was c# and I ran it through a c# to

>vb

>converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

>...but it is not correct.. what did it or I do incorrectly?

>this is the c# code

>public static void EasterSunday(int 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(ByVal 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

>







-

Re:Calculate Easter Sunday

PSC = www.Planet-Source-Code.com">www.Planet-Source-Code.com



Thought everyone knew. Excellent resource.



Mike



On Sun, 13 Apr 2008 13:36:44 -0400, in

microsoft.public.dotnet.languages.vb "Brian"

<bsgallatin@community.nospam>wrote:



Quote
what is PSC?

<Just_a_fan@home.net>wrote in message

news:pok304htit8pnrhctisuogq280leuaag8a@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.public.dotnet.languages.vb "Brian"

><bsgallatin@community.nospam>wrote:

>

>>Hi, I found this code on the web.. it was c# and I ran it through a c# to

>>vb

>>converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

>>...but it is not correct.. what did it or I do incorrectly?

>>this is the c# code

>>public static void EasterSunday(int 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(ByVal 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

>>

>





-

Re:Calculate Easter Sunday

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



<Just_a_fan@home.net>wrote in message

Quote
PSC = www.Planet-Source-Code.com">www.Planet-Source-Code.com



Thought everyone knew. Excellent resource.



Mike



On Sun, 13 Apr 2008 13:36:44 -0400, in

microsoft.public.dotnet.languages.vb "Brian"

<bsgallatin@community.nospam>wrote:



>what is PSC?

><Just_a_fan@home.net>wrote in message

>news:pok304htit8pnrhctisuogq280leuaag8a@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.public.dotnet.languages.vb "Brian"

>><bsgallatin@community.nospam>wrote:

>>

>>>Hi, I found this code on the web.. it was c# and I ran it through a c#

>>>to

>>>vb

>>>converter( labs.developerfusion.co.uk/convert/csharp-to-vb.aspx">labs.developerfusion.co.uk/convert/csharp-to-vb.aspx

>>>...but it is not correct.. what did it or I do incorrectly?

>>>this is the c# code

>>>public static void EasterSunday(int 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(ByVal 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

>>>

>>

>







-