Results 1 to 6 of 6

Thread: Please help.

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Please help.

    I am trying to write a program to determine if a year is a leap year or not. It is driving me nuts, i know nothing about leap years. Here is the question.

    "The current calendar, called the gregorian calendar, was introduced in 1582. Every year divisible by four was declared to be a leap year, with the exception of the years ending in 00(that is, those divisible by 100) and not divisible by 400."

    i cant figure out how to even go about it, here is as far as i got with my coding.
    Code:
    Public Class Form1
    
        Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
            Dim year, value, value2 As Double
            year = CDbl(txtYear.Text)
            value = year / 100
            value2 = value / 4
    
            MessageBox.Show(CStr(value2))
            
    
        End Sub
    End Class

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Please help.

    try this:


    vb Code:
    1. MsgBox(Date.IsLeapYear(1582))

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Posts
    14

    Re: Please help.

    thanx alot dude, i never would have thought of that

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Please help.

    If this is homework, your teacher may not accept Paul's solution since the purpose of the exercise is to help you learn how to turn an algorithm into code.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Please help.

    you can calculate leap years easily, using the specifications you provided in post #1:

    vb Code:
    1. Dim Y As Integer = CInt(txtYear.Text)
    2.  
    3. If Y Mod 4 = 0 And Not Y Mod 100 = 0 Or Y Mod 4 = 0 And Y Mod 400 = 0 Then
    4.    'is a leap year
    5. End If

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Please help.

    look at

    Math.DivRem
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width