Solved

Calculation for leap year?

Posted on 2007-11-19
6
679 Views
Last Modified: 2010-04-21
I am currently trying to calculate if a year is a leap year or not. arrYear(i) would be just a input for the year..

So, I entered the year 2008 and it return a false. What gives?
Dim blnLeapYear As Boolean = ((arrYear(i) Mod 4 = 0) And (arrYear(i) Mod 100 = 0)) Or (arrYear(i) Mod 400 = 0)

Open in new window

0
Comment
Question by:Sharalynn
  • 3
  • 2
6 Comments
 
LVL 10

Assisted Solution

by:joex911
joex911 earned 200 total points
Comment Utility
Hi, there's a built-in function that does that for you:
Dim blnLeapYear As Boolean = DateTime.IsLeapYear(arrYear(i))

Open in new window

0
 
LVL 9

Accepted Solution

by:
codeclay earned 300 total points
Comment Utility
Dim blnLeapYear As Boolean = ((arrYear(i) Mod 4 = 0) And (arrYear(i) Mod 100 <> 0)) Or (arrYear(i) Mod 400 = 0)
0
 

Author Comment

by:Sharalynn
Comment Utility
Thank you both so much!

For some reason the built-in function returns an error:
Year must be between 1 and 9999.
Parameter name: year

However the 2nd one works great. I must have done the 1st one wrong somehow. Just fyi, I get the value from a dropdownlist using something like ddlYear1.SelectedItem.Value
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Closing Comment

by:Sharalynn
Comment Utility
Nice!
0
 
LVL 10

Expert Comment

by:joex911
Comment Utility
Well as the error says you're sending a number that is either lower than 1 or higher than 9999, maybe you got a null or empty value in your DropDownList?, it's always good to add validations so that exceptions like that are not raised.
0
 

Author Comment

by:Sharalynn
Comment Utility
That's weird because after the value has been retrieved, the 2nd one work for me but the first one didn't. I also made sure the value has been converted of type Integer first. There are only 3 year values as well. No idea what happened there. Ah well, it works out in the end anyway. Choices are good!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now