Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Setting a Leap year condition

Setting a Leap year condition

Scheduled Pinned Locked Moved Visual Basic
helpdata-structuresjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bensoncd
    wrote on last edited by
    #1

    I have written a programme that should allow a pupil to enter his details and then the programme will display the pupil’s profile using a dialog box. I have worked the rest fine but I have difficulty in setting the leap year limits for the month of February. I have tried juggling around my code in many different ways, but seem not to get it right. I have left the code with an array of 10 leap years that I consider to fall within a pupil’s age. I definitely know that the problem is not with coding an array, it’s something else. I have said: For Leap year 1 To Leap year 10 If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) <> Leap year And [Day is ("29") Or ("30") Or ("31")] Then ErrorMessage1 Exit Sub End If If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) = Leap year And [Day is ("30") Or ("31")] Then ErrorMessage2 Exit Sub End If However, an error exist somehow in the code, may you give me an idea of where the problem is. Been always great to be part of this forum, especially when I know they know more than what I know…..

    I 1 Reply Last reply
    0
    • B bensoncd

      I have written a programme that should allow a pupil to enter his details and then the programme will display the pupil’s profile using a dialog box. I have worked the rest fine but I have difficulty in setting the leap year limits for the month of February. I have tried juggling around my code in many different ways, but seem not to get it right. I have left the code with an array of 10 leap years that I consider to fall within a pupil’s age. I definitely know that the problem is not with coding an array, it’s something else. I have said: For Leap year 1 To Leap year 10 If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) <> Leap year And [Day is ("29") Or ("30") Or ("31")] Then ErrorMessage1 Exit Sub End If If the month is "February" And CInt(The “Value” of numeric-up-down representing the pupil’s year of birth) = Leap year And [Day is ("30") Or ("31")] Then ErrorMessage2 Exit Sub End If However, an error exist somehow in the code, may you give me an idea of where the problem is. Been always great to be part of this forum, especially when I know they know more than what I know…..

      I Offline
      I Offline
      Ian Darling
      wrote on last edited by
      #2

      You might want to learn what the rules for leap years are: If the year is divisible by 4 then it's a leap year. However, if the year is also divisible by 100, then it is not, but it it's divisible by 400 then it is. Hence 2000, 2004, 2400 are leap years, but 1900 and 2100 are not. A leap year has one additional day, which is February 29th. ------------------ If you're using .NET, just use DateTime.Parse or something to see if the date entered is valid or not (as the DateTime APIs handle this stuff anyway, so you're better off using them). VB6 may have a similar API.


      Ian Darling "One of the few systems...which has had “no deaths” in the reliability requirements." - Michael Platt

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups