Why is this not working and how to fix??

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

I am trying to populate a listbox with dates of easter from 1901 to
2099. My code is not doing it. Here is what I have. What am I doing
wrong?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim a As Integer = 0
Dim b As Integer = 0
Dim c As Integer = 0
Dim d As Integer = 0
Dim g As Integer = 0
Dim easter As Integer = 0
Dim easterinapril As Integer = 0
Dim i As Integer = 1900

a = (i) Mod 19
b = i Mod 4
c = i Mod 7
d = (19 * a + 24) Mod 30
g = (2 * b + 4 * c + 6 * d + 5) Mod 7

easter = (22 + d + g)
easterinapril = (easter - 31)
Do
While i < 2099
If easter > 31 Then
lstResult.Items.Add("April " & easterinapril & ", "
& i)
Else : lstResult.Items.Add("March " & easter & ", " &
i)
End If
End While
i = i + 1

Loop

End Sub
 
Suppose you give us a hint about what it's not doing right?

Tom Dacon
Dacon Software Consulting
 
Change:

Dim i As Integer = 1900

to:

Dim i As Integer = 1901

otherwise you are starting at 1900 instead of 1901.

Delete the 2 lines:

Do
Loop

otherwie you have an endless loop.

Change:

While i < 2099

to:

While i <= 2099


otherwise you are ending at 2098 instead of 2099.

Move the line:

While i <= 2099

to directly before the line:

a = (i) Mod 19

otherwise you are prodicing the same result for every year.

Move the line:

i = i + 1

to directly before the line:

End While

to make the loop work correctly.

And ... Voila!
 
Anyone know of a way to convert a HTML Table to CSV or Datatable? It's in
the form of this format It's basically a multi row x 7 column HTML table...
all in standard HTML <TABLE> tags thanks!
 
whoops posted to wrong spot

Smokey Grindel said:
Anyone know of a way to convert a HTML Table to CSV or Datatable? It's in
the form of this format It's basically a multi row x 7 column HTML
table... all in standard HTML <TABLE> tags thanks!
 
Only if you want the dates of easter in it.

Try starting a new thread, giving your post a meaningful subject line and
punctuating your post so that ic can be understood.
 
Stephany Young said:
And ... Voila!

Yet it apparently still does not compute Easter :-)

http://en.wikipedia.org/wiki/Computus

From what I can see the OP is suing "Gauss's algorithm" (though not exactly)
which contains (according to Wikipedia) two exception dates. And as it
points out requires a table (which is why the OP is limited to dates between
1900 and 2099). Other ranges require other magic numbers.

If the OP reads the link above (or perhaps he has) he might want to test the
Meeus Julian algorithm which is "valid for all Julian years and has no
exceptions and requires no tables" which sounds like a plus to me.

Tom
 
Absolutely Tom!

Note that I did not comment on the validity of the algorithm the OP was
using (the Meeus Julian algorithm), but for the year range 1901 to 2099, it
does actually get it right. Off the top of my head I think it works for that
range because 2000 was a leap year, but it will not probably not work 1900
because that wasn't a leap year (2100 is isn the same boat).

I use the Meeus/Jones/Butcher Gregorian algorithm which is valid for all
Gregorian years, but one still has to be careful for years prior to 1753
because down in this part of the world we use the Gregorian calandar as
adopted by Great Britain in 1752 as a result of the Calandar Act of 1751. In
Italy and Spain (and some other countries) it will be good for years later
than 1582.

Of course it is only good until such time as we change the calendar again.
:)
 
To add a little bit for your knowledge in New Zealand.
I use the Meeus/Jones/Butcher Gregorian algorithm which is valid for all
Gregorian years, but one still has to be careful for years prior to 1753
because down in this part of the world we use the Gregorian calandar as
adopted by Great Britain in 1752 as a result of the Calandar Act of 1751.
In Italy and Spain (and some other countries) it will be good for years
later than 1582.

Before 1583 had all Major European countries of those days beside England
and Turkey adopted the Gregorian calendar.

Those included Spain, France, Polen/Lituanien, Holland/Zeeland.
 
thanks for all the help everyone. Ok so there are exception years and
I am trying to write this code in for the exception years, anyone see
what i am doing wrong:

easter = (22 + d + g)
easterinapril = (easter - 31)
easterspecialyear = (easter - 7)

'for years 1954, 1981...etc. use this (easter-7) or (22+d+g)-(7))
'the below does not work, do i need it somewhere else in my if
statements to make this work correctly?

If CInt(txtYear.Text) = 1954 Or CInt(txtYear.Text) = 1981 Or
CInt(txtYear.Text) = 2049 Or CInt(txtYear.Text) = 2076 Then
lblResult.Text = easterspecialyear
Else
If CInt(txtYear.Text) < 1901 Or CInt(txtYear.Text) > 2099
Then
lblResult.Text = "Please enter a valid year"
ElseIf easter > 31 Then
lblResult.Text = "Easter in the year " & txtYear.Text &
" " & "is on April " & easterinapril
Else
lblResult.Text = "Easter in the year " & txtYear.Text &
" " & "is on March " & easter


End If
End If


End Sub
 
Back
Top