473,385 Members | 1,630 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

would you mind helping a lamber

jbw
i am trying to get a value of true if a user of my program selects a leap
year from a combobox.
can someone help me to correct this code so that i can do this using a
simple loop, rather than having to write a list 100 years long?

here is the code that i am trying to work with using vb.net

Private Sub yearBox_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles yearBox.SelectedIndexChanged

Dim lYear As Boolean

Dim x As Integer

Dim leap As Short

x = 3

For x = 3 To 115

If x + 4 = yearBox.SelectedIndex Then

lYear = True

Else : lYear = False

End If

totaldaysbox.Text = lYear

Next x

End Sub
Jul 21 '05 #1
5 1339

"jbw" <za*****@hotmail.com> wrote in message
news:un**************@TK2MSFTNGP10.phx.gbl...
i am trying to get a value of true if a user of my program selects a leap
year from a combobox.
can someone help me to correct this code so that i can do this using a
simple loop, rather than having to write a list 100 years long?

here is the code that i am trying to work with using vb.net

Private Sub yearBox_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles yearBox.SelectedIndexChanged

Dim lYear As Boolean

Dim x As Integer

Dim leap As Short

x = 3

For x = 3 To 115

If x + 4 = yearBox.SelectedIndex Then

lYear = True

Else : lYear = False

End If

totaldaysbox.Text = lYear

Next x

End Sub

Store the value of the year in question in an integer, then apply the
following algorithm (assuming the value is stored in intMyYear):
If ( intMyYear Mod 400 = 0) OR (intMyYear Mod 4 = 0 AND intMyYear Mod 100 !=
0) Then
' it's a leap year
Else
' it's not a leap year
EndIf
You probably already know that Mod = modulus division, which returns the
remainder.
You'll have to translate the above into proper VB syntax.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 21 '05 #2
From MSDN (little bit changed)

Dim TempDate as string = "1/31/" & ToTestYear
TempDate = DateAdd("m", 1, TempDate)
If Day(TempDate) = 29 Then IsLeapYearDate = True

Clever routine, I like those

Cor
Jul 21 '05 #3
There's already an IsLeapYear Method in DotNet, Why try to write your own?

IsLeapyear = Date.IsLeapYear(year_to_test)

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
From MSDN (little bit changed)

Dim TempDate as string = "1/31/" & ToTestYear
TempDate = DateAdd("m", 1, TempDate)
If Day(TempDate) = 29 Then IsLeapYearDate = True

Clever routine, I like those

Cor

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.683 / Virus Database: 445 - Release Date: 12/05/2004
Jul 21 '05 #4
Hi Mick,

That was what I was thinking also, however did not see it that fast.

Thanks you for pointing me on that.

Cor
Jul 21 '05 #5

"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:u8*************@TK2MSFTNGP12.phx.gbl...
There's already an IsLeapYear Method in DotNet, Why try to write your own?
IsLeapyear = Date.IsLeapYear(year_to_test)

Thanks, Mick! I didn't think to look.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Jul 21 '05 #6

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

Similar topics

7
by: mir nazim | last post by:
IT IS A LONG TIME I HAVE POSTED TO THIS GROUP AND NO ONE SEEMS TO BE INTERESTED IN HELPING ME. WHAT R U PEOPLE DOING HERE
11
by: Arthur T. Murray | last post by:
Now, suppose that you wanted to write an AI in Python that would implement your mind-model and allow it to grow, mutate, develop. Here is one possible scenario. It would not be necessary to do...
4
by: Graham Like | last post by:
I read a lot about serialising things to XML. Can someone give me some examples of why I would want to do this? I seem to be missing the point.
39
by: Antoon Pardon | last post by:
I was wondering how people would feel if the cmp function and the __cmp__ method would be a bit more generalised. The problem now is that the cmp protocol has no way to indicate two objects are...
4
by: smerf | last post by:
I like UltraVNC for helping remote users, and the authors have a server called Nat2Nat that you can hook up to to get thru firewalls without having to set up ports and such. Problem is that...
1
by: tommak | last post by:
It's a dream of human beings to build machines that can think and behave like human beings. The most important part of of such a machine is an artificial mind that can emulate the cognitive...
0
by: im20 | last post by:
I am helping a polish up a client's PPC campaign and when of the problems I have run into is that the real estate backend system he is using, does not allow the ability to link directly to a...
21
by: Osiris | last post by:
suppose I wanted to make availble on the WWW a facility to do some rather floating-point-calculation-intensive stuff. I can do that in PHP, but then all work must be done on the hosters' computer...
13
by: camphor | last post by:
hi, would anyone know if there is a php script to Accept the Terms & Conditions. The customer must check the Terms & Conditions box before he/she is able to go to the next page. Not really sure...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.