would you mind helping a lamber

  • Thread starter Thread starter jbw
  • Start date Start date
J

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
 
jbw said:
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.
 
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
 
There's already an IsLeapYear Method in DotNet, Why try to write your own?

IsLeapyear = Date.IsLeapYear(year_to_test)
 
Hi Mick,

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

Thanks you for pointing me on that.

Cor
 
"Mick Doherty"
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.
 
Back
Top