Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calculation for leap year?

Posted on 2007-11-19
6
Medium Priority
?
697 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 10

Assisted Solution

by:Oliver Amaya
Oliver Amaya earned 800 total points
ID: 20312027
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 1200 total points
ID: 20312126
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
ID: 20312888
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

by:Sharalynn
ID: 31409921
Nice!
0
 
LVL 10

Expert Comment

by:Oliver Amaya
ID: 20313278
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
ID: 20318852
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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