how to fix this IF statement ?

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

Ron

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
 
Ron,

I don't know what you want (what the problem is), however two things all was
it to make it for us easier to understand your code.

Set option strict to On and use the short circuit OrElse (and if needed the
AndAlso)

Cor
 
Ron: I tried to point out in my other reply that (I believe) you are using
the "sub-optimal" algorithm. As a result of that choice (the one with the
table values and limited range) you're stuck having to handle the exceptions
as well.

There are three things you should do when you get stuck coding. In order of
priority they are:

1) Pseudocode
2) Pseudocode
3) Pseudocode

Rather than write in BASIC:
If CInt(txtYear.Text) < 1901 Or CInt(txtYear.Text) > 2099

Consider simply writing:
IF IsInvalidDateRange()

When the pseudocode is ready (i.e. you can see it will work) the pseudocode
can be translated into VB.Net, C# or Java or assembly language. And by
partitioning the problem each piece of functionality can be tested
independently. If for some reason it runs too slowly calling functions
(which it won't) you can optimize "after" you have it working.

"If you can't write it in English you can't write it in a programming
language"
Tom Leylan
 
Back
Top