Calculate Easter Sunday

B

Brian

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/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
 
J

Jack Jackson

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/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.
 
J

Just_a_fan

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

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top