473,499 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to fix this IF statement ?

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

Jan 26 '07 #1
2 945
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" <pt*****@yahoo.comschreef in bericht
news:11**********************@v33g2000cwv.googlegr oups.com...
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

Jan 26 '07 #2
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
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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" <pt*****@yahoo.comschreef in bericht
news:11**********************@v33g2000cwv.googlegr oups.com...
>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

Jan 26 '07 #3

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

Similar topics

28
3538
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
2777
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
2520
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
3243
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
2682
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
2905
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
2673
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
8340
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
7924
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
2040
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.