473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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(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
Jun 27 '08 #1
6 3110
On Sun, 13 Apr 2008 00:34:59 -0400, "Brian"
<bs********@community.nospamwrote:
>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(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.

Jun 27 '08 #2
Thanks that did it... didn't relize the difereance between / \

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:5d********************************@4ax.com...
On Sun, 13 Apr 2008 00:34:59 -0400, "Brian"
<bs********@community.nospamwrote:
>>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(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.

Jun 27 '08 #3
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"
<bs********@community.nospamwrote:
>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(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
Jun 27 '08 #4
what is PSC?
<Ju********@home.netwrote in message
news:po********************************@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"
<bs********@community.nospamwrote:
>>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(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

Jun 27 '08 #5
PSC = http://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"
<bs********@community.nospamwrote:
>what is PSC?
<Ju********@home.netwrote in message
news:po********************************@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"
<bs********@community.nospamwrote:
>>>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(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
Jun 27 '08 #6
thanks.. I'll go check it out...

<Ju********@home.netwrote in message
news:0t********************************@4ax.com...
PSC = http://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"
<bs********@community.nospamwrote:
>>what is PSC?
<Ju********@home.netwrote in message
news:po********************************@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"
<bs********@community.nospamwrote:

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(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


Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Michael \(michka\) Kaplan [MS] | last post by:
A little light humor... this "easter egg" was hidden deep in the Access 95 help system. I did not write it (I am not this creative and never was) and I did not put it in the product (I was not on...
2
by: Gustavo G. Rondina | last post by:
It is possible to caclulate every year's easter using simple mathematical operations. Here is a code that does the trick: http://www.brlivre.org/c/easter.c I found the math scheme in an...
5
by: Hardy Wang | last post by:
Hi: Are there any algorithms I can use, that based on a given date and a culture code (different cultures may have different beginning of week), I can get first and last date of the current week?...
9
by: griemer | last post by:
Hi every one, Is there a way to calculate the timestamp of 00:00:00 last Sunday. For me, this is the begin of the current week.. Or, how old is this week, in seconds Any ideas? Regards,
32
by: barkarlo | last post by:
In my table date/time field (starttime,endtime) include both date and time. How can I calculate worktime in query for each employee who works sundays? for an example: sometimes starttime and...
0
kudos
by: kudos | last post by:
Hi, a couple of months ago, I made a xmas chistmas "card" to this community(http://www.thescripts.com/forum/thread580722.html) Now its soon easter, and I hacked together something for easter as...
37
by: mazwolfe | last post by:
I'm new here, so excuse me if my style is incorrect. Can anyone come up with a better method for this calculation? Code: int is_leap(int year) { switch (year % 19) { case 0: case 3: case 6:...
4
by: khicon73 | last post by:
Hello All, I would like to calculate weeknumber and period from first day of the week (sunday) and last day of the week (saturday) and week number falls from 1 to 52 only. If week number >= 53 then...
4
by: muddasirmunir | last post by:
i am using vb6. what i need is to calculate X (means any ) working day date skipping holidays (saturday and sunday) or (friday or saturday in some contries) for example: today is 20-06-2008...
2
by: Mike | last post by:
Is there a way to calculate the total number of weekdays when provided a date? Example: If I have a start date of 7/11/2008 and I want to go out 10 days, I want to get this: 6 weekdays 4...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.